{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sympy - Symbolic algebra in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "J.R. Johansson (jrjohansson at gmail.com)\n",
    "\n",
    "The latest version of this [IPython notebook](http://ipython.org/notebook.html) lecture is available at [http://github.com/jrjohansson/scientific-python-lectures](http://github.com/jrjohansson/scientific-python-lectures).\n",
    "\n",
    "The other notebooks in this lecture series are indexed at [http://jrjohansson.github.io](http://jrjohansson.github.io)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two notable Computer Algebra Systems (CAS) for Python:\n",
    "\n",
    "* [SymPy](http://sympy.org/en/index.html) - A python module that can be used in any Python program, or in an IPython session, that provides powerful CAS features. \n",
    "* [Sage](http://www.sagemath.org/) - Sage is a full-featured and very powerful CAS enviroment that aims to provide an open source system that competes with Mathematica and Maple. Sage is not a regular Python module, but rather a CAS environment that uses Python as its programming language.\n",
    "\n",
    "Sage is in some aspects more powerful than SymPy, but both offer very comprehensive CAS functionality. The advantage of SymPy is that it is a regular Python module and integrates well with the IPython notebook. \n",
    "\n",
    "In this lecture we will therefore look at how to use SymPy with IPython notebooks. If you are interested in an open source CAS environment I also recommend to read more about Sage.\n",
    "\n",
    "To get started using SymPy in a Python program or notebook, import the module `sympy`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from sympy import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get nice-looking $\\LaTeX$ formatted output run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "init_printing()\n",
    "\n",
    "# or with older versions of sympy/ipython, load the IPython extension\n",
    "#%load_ext sympy.interactive.ipythonprinting\n",
    "# or\n",
    "#%load_ext sympyprinting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Symbolic variables"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In SymPy we need to create symbols for the variables we want to work with. We can create a new symbol using the `Symbol` class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = Symbol('x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAbBAMAAAAt2dQtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABYElEQVQoFY2SMUjEQBBFf+4kiSTGqGBhlUKw\nVcFO8IQUIihyYGWTTu1iIRaiXqWW1tpY2Qhq4VU2EQ6usrDWwtJG1FYCcXZn4xI8kptidubvY3aW\nGaDK2nNJFQLHH2pUQqbvfVdDl8ZPJQTYaR+QGfcBtYkxAnK9reaTXlsjN9YbkOoz+WvcAIslUAfw\nlk7nuZrmTnRIkRNjMMu+YIp3tRUh94xvxjUgoiKEZb7dpaN7MLEfc6ogKyOjb62zOgu4d7VNs1GA\nHt53pkZImWR1i9pLnNRWrXElr+X4h+L+mKFzqoSBaZnch+F2GK6IuI5XcXwKBxAEDKuOdOMfiMSF\ngug5it+EF5b/rgk5+ytWqXE7OYKVcKogN4XcItU4zfi2tYBRZvJKVoQLoWywTAWf9rrNgLMcqgd4\nEcoqy6VjMSKG5LpwKPyjDimiAbPNFORi0snTsqX7K2AEOf7vlOtL6i9nYkLvuMXjdgAAAABJRU5E\nrkJggg==\n",
      "text/latex": [
       "$$\\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "       2\n",
       "(x + π) "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pi + x)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# alternative way of defining symbols\n",
    "a, b, c = symbols(\"a, b, c\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sympy.core.symbol.Symbol"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can add assumptions to symbols when we create them:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = Symbol('x', real=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.is_imaginary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = Symbol('x', positive=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACoAAAAPBAMAAABgjEDtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA782r3SJ2ZjIQmUS7\nVIlAnjihAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAv0lEQVQYGWNg/GQs72z0hQEV8Acw5BcwNKIK\nMsxiAIkyo4mGg0XZJqAKR4BFOUCi0Q2c3QFwWaAJ3Iq5j0LXH+A9n8DAuvwxWAooysC4dn4B0wEG\n/gSGLRO4JUEaQKJMDgwMPGBROQYGMaAgRNQAKsrxq7zcHC66ACrK/hckBARgExbA1H4DiyFEmQ8w\nxCcwODEwTIOpZQGqZRdguHiSob+AYSUDA/caeZkV3Of/XGBgeJc2RWQCp1XeBKghaBQAM0c287zN\nvm0AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\mathrm{True}$$"
      ],
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x > 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Complex numbers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The imaginary unit is denoted `I` in Sympy. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACoAAAAQBAMAAACSDPCjAAAALVBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAOrOgAAAADnRSTlMAVO8Qq5l2zWaJ3SK7RPx7\nN2kAAAAJcEhZcwAADsQAAA7EAZUrDhsAAABySURBVBgZY2DABCwHGBgYldHFWRoYTEIeQ0UZE5Ck\n2SgRNQsDmoRhwoRLWES5BcLhopzl5VXq5eUODAzMDM/gokAGzGWMIEdhmMvuYIBF1E5gAhbRe9wN\nDKxOzz2A5gABzFyWDggfQsJEkcWATtoA5wMA/Fcc5MixWvAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1 + i$$"
      ],
      "text/plain": [
       "1 + ⅈ"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+1*I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAPBAMAAAAMihLoAAAAJFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAEM3dMlTvq5l2ZtVdCTcAAAAJcEhZcwAA\nDsQAAA7EAZUrDhsAAAAqSURBVAgdY2DAClgTEcLi7RsRHAZOMjlCxiCgwkC2ATA3cJRtqoKxwTQA\nC0AL2ft3JesAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$-1$$"
      ],
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "I**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAbBAMAAAAkMnRXAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRImr\nEDIioekeAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXElEQVQ4EY2SPUvEQBCG3z0xauKeQUEsg4i9\ngqVwYgqRIDZWWlhYaJcmWB1i40chXm2jlRaClYeVyJ2IpRHs/BHGykPQczYTwq0mXgayzLzzZIbZ\nHaC71WfC7hAse7BSADPs8nsR7Ex8FsCA/q9CmOEXwupECYeOPCvZlCkt0zFC330ehgZlLnEFzJHT\nzMQO6VZfgPLCwSxX1Kh9juTDE2GWj4F2O4KhumuWYMAOYbLGuVENUYGGYZHzAf0R+JDbjYsbVnRs\nhcVp6m/W8IpJfyMLm2BxExjrreAWd+FuFrbH4gkQDvkIMR/H16675bpe7KsR8JZiOFbxB8e/R0gw\nagpP0iV+Z2PnLNMIsmXhqC9ClRV90mQEen0zGjZbPZFwsrBVFlXRpiMfq8E4C+n1rp16DrDE6j+P\npQCxzli8TOwm53NnRE/PNtWp/vFpkdjUWuZbWkQ4+RDiJaf8DywZUcb5dpcnAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left(i x + 1\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(ⅈ⋅x + 1) "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x * I + 1)**2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rational numbers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are three different numerical types in SymPy: `Real`, `Rational`, `Integer`: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "r1 = Rational(4,5)\n",
    "r2 = Rational(5,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAsAAAAqBAMAAACXcryGAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBU\nq0Qb3U6NAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAkklEQVQYGWNgYGAQAmIgMAGTrClgqmIKmFoA\npjgKwNRWBjC1AEzxCICpXQxg6uzdu9+ugnVAtDN8AXOW/L8Bpski/oPAB6K0Tt0gdACoMP//L5Dy\nWVcLQNQFEAGnbrQqgnjeDPUPQDQDiwGYYvrOwMA7gYHrHwMD2wQGpt8MDEwMDMwTGBjYFRjaQMYU\nrdVmYAAALnIpDsFeUO4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{4}{5}$$"
      ],
      "text/plain": [
       "4/5"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAqBAMAAACuFQ3dAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBU\nq0Qb3U6NAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA5UlEQVQYGWNgYGAQAmIYMAEyjm0A81hTGLgv\n3YewK6YAheIh7AUINkcBgr2VAcFegGDzCCDYuxgQ7LN37367CjeTIQVhPsMXBHvJ/xsMuvlzG4Ai\nNAb/4eADZTYVqTgyMGxasRBoCvcFhvUPGOYwbC5gYODdwMCWwJHAwDWBgYHNgIH3I8sFBp7fDAyc\nv4Fs/gsMfH/A1jL/3q/AwPcVzH6/oH4BA+MvMNuWoV4BymZSYICrCWJgAOrlAenlUWAoZ3Fg4ACa\nCYrRcKBdTEC72K1W6Row2DBsEwDaBfSjAcOu0IsMDACGnlMXi4yUmQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{41}{20}$$"
      ],
      "text/plain": [
       "41\n",
       "──\n",
       "20"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1+r2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABUAAAAqBAMAAACuFQ3dAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWaJMkS7\nIt2ZnNffAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA/klEQVQYGWNggICZmQtADCEDBgbzDawFDAzM\nrv5A9lEGngMg8XwDBu6/IAYQANk8CmAWmM1fNS0azAOK21cwMAmAOCD2ZwZWZSib/wEDx28om6+A\ngeMHlM2igBDnAqpXgIozeDIYgcwJ0S9pYOAM9QIJ0xj8h4MPlNl0NeYUA0OZwVKg+5kdGOZvYND/\n/xNoIosBA5MCQ6XbBSCb6QEDyy8GB7A97J8RbKAA32cGj7YosAzD/gkMhxnubwBznoBIngcgkjUA\nTIKjIxVocAEDJyhsGQMY7jIVMLB+BrKXMjDksgINK2Bg4H05M+QBbwBDE9BidqAfHzBcnRLMwAAA\nq1hKQiigoh8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{16}{25}$$"
      ],
      "text/plain": [
       "16\n",
       "──\n",
       "25"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1/r2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Numerical evaluation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SymPy uses a library for artitrary precision as numerical backend, and has predefined SymPy expressions for a number of mathematical constants, such as: `pi`, `e`, `oo` for infinity.\n",
    "\n",
    "To evaluate an expression numerically we can use the `evalf` function (or `N`). It takes an argument `n` which specifies the number of significant digits."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgsAAAAPBAMAAACYf5HCAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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RWjtA9R5Ad\nJZPcQil6y2my5NQcR4qm7NSL5a3jCaSKdVejD6CIkC1uX2iDpCrH9auEnEJKW0IgBtkDccPCXxm+\nAdgNbP3waI0fhs15t1Kb5/iaGb6Pr8xmk+dNevhX5m3gy7VneAv/C2Th3rn+SaB/mEPKXoWyFPYc\noX/fTIa46N/aCDSz3Kk5yhFNVp4f/OMJpIpF659rwCNCOje96Xyt86eVeZfqOb4SKyH9Qrq2VYG4\nuErRtoiwcMr5//oXWhd7due/PDYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$3.1415926535897932384626433832795028841971693993751$$"
      ],
      "text/plain": [
       "3.1415926535897932384626433832795028841971693993751"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi.evalf(n=50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "y = (x + pi)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHUAAAAbBAMAAACw1N2lAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACJElEQVQ4EZ2UP2hTURTGv6RJ+sy7/aOigw6+\nis7GduqUFIKDU7A6CC1UqFS6+JYiIpKAi5Md6mClpW8SnHwiIYMgd7I4iEW6dChmcHOISKhLJT3n\n3HdfWnkUfQfyzrnnfL97T07eDZDO3OmZdCBRb7Gdmr2DzmhaeBEXgrQssKzTswvpUbdGbMajx//Y\nmIgv8/N0Epd5/65xKD/Mh7C5rQ8Y4gEXw2IbmOLc33YGzi/JOWvsCiWAI3UdN6EqlPn+9IlG1m7J\nGji+ONQb2OPo8+w+u4clEw3UMAG0KLPR69GW3EFsln0dqK4kB5nNXKJzOXoj4k9WftYG4i1LHZie\nhXVzETspolwQMUvkNx+fe+TLus9+DCUh7Jhluz+WAiBfkxIwThMIswuFiqxj9vxdLQlmlR+xquvh\nBZCtSAm4R4PX7r4zKuuYhftSEsy6sGxP47aGMxexJFFSI021eu15tbplKquaPbPPLMuzvxJg+KdR\nQLYf8aOVPfckUG5wjlgVxuw8sV6fpZ6BTpufZJal5mLW2d39tu5LBztybnFOtDIrR9cxqGVt2RXg\nvkyAewZOlEz3Hfq+h2bVpF+8UcYpQeNzL8L5jS8VQwAjETsUKppzPjRivKIX78HmDe8oW7w1HaCw\nhfxO9ysNsfzHM1Fztg3k6COW/E5GxWQXv4pH74KSL5mMxFm+C8au2uBfvdxBI068+8ftM9DvLeMd\nJ0yomf8cKhwAL6SHm0ESaMoAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x + 3.1416\\right)^{2}$$"
      ],
      "text/plain": [
       "            2\n",
       "(x + 3.1416) "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N(y, 5) # same as evalf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When we numerically evaluate algebraic expressions we often want to substitute a symbol with a numerical value. In SymPy we do that using the `subs` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFYAAAAbBAMAAAAUvmV2AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlElEQVQ4EY2TO0jDUBSG/1QSLUkfKLqaQRA3\nLbh1qBBQlEoXJx901EGog651sro5u7STiyAKdlQiuFsFcdRFcFNBFxXiOffePBpEcyDn8Z+vNyfJ\nKZDQ2pNuQhJmPlNKyhr57FtitqV9JmWBvu/krFFLzrYJ1Wxyf1oqT+1UhdxAyE27T9thFWY3lB7h\nGJiiZM8Vjab3JWLcXQHZmd0in23dPUh27p7vxtaQQXmzhrTnvcLgdt0Vakf14qy1LxtDHP5hMSvZ\nzQh7O7oixWCGuud5H8CClAsRtojhllTVvOZFo3+DhhyR6mqEBXqqXAbzPuO095HKHbrIDtipeQGd\nl+nMcdYcp8wNjGdc8i+cdrG0oaZaJv+dZTsGQ4qNzJAuQVfL5LO6nXOJPeQfAJFn0wGjJMTgPVy7\nuRYp6tl4fXhe6x1aBWP8Zcj8c7eQPqFyUYji+OVm2cY6MHi+JMWALSDD7LyUxTdWRBj8c6WiVWUU\nexlCKrvsUmh3pE10yb8WtJPSIrvuS/EYHKfZ8Va8Fv8hEn8A9AZYsVBvIRkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(1.5 + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(1.5 + π) "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.subs(x, 1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAPBAMAAACRq9klAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC7klEQVQ4Ea2UTWhUVxiGnzuTOz+ZmWTMRqwL\nb2MbFREjNqCCJGRhoZvclQtpyRCo+JsMURwU0UvBhbqIUiKxRRxc6KILZ2PrQnAMlFJoyVBKoRu9\nbhRRoqLRmDG5vufcaTbdeuC+95z7fueZ7zs/g9O9dYD/Wu7Xtk3qt3ktWVnZCV//th661n4BTuVI\nA9Inj7birXPHH2zg/jEe8NVIpVJmN+l5KEzamGwUldVp743F8XgQ4pFquCVOB3RRWMK9zUbZ//pY\nh6vRW0jAYZ5HUVTiW7jM7p45xUDu2D3z+t0AJflFOquFEKeW8sleYKbBAkmPrbgjYz7W4ZdDRbgP\nq/kUUvADjA2Qj4EaqzlPBTSSmWK4lu7FrWarpF5zNnCbTGi+2oyPdSiZ0RHYQxm0GHf9/wHTOQGt\noJIzr/x0mJszQC3NEtsNwAKtEwMn+jilj5m6sbjpL2c4Oz0ADw3QCu4NFbBkYmk3Rewp0/xyOlBP\nGcbO6LPPVGr0ONTHpB5htaitkpO+M49bF9AKzonPlWt0y4RNlGHlNd9thlzR0ACt08eaAE43NbZZ\n6qdLy0B920EaAa1oeDzgn3PvAvWu6yE95UY+GzTZAFtOskph380pcF+YGLr1tDJUb3PxbwO0omF2\nsqPEzKQOhqeRToS/AM8DC2w5JF7yiPw7LVzNhOQ9I/EuH1TuZ8oCukZwiiQXs0XaFmFaUSugv/GT\ngKEFWidVMwf5Igw14vPLX2ZeC/ijMvxm796xS38aqXfOCTgs0igFTzhV29/Yv5yhdbI1EnOm1lTI\ncEmxumb5ZaAHSoBsbyx6t79UHmxhEO7xvU5EcUhrKFtraJ2ENqFmMkwWGdJ8PqmMH4hLHq7pbnXI\notMAJR0hD+qZW3TUnRuVniqzFN6TKrutXY4djydFzvs806E1wLtRtEBif3PU7LazbsTXVva/CWP5\nrnsb7Fq3npyuaZVM99oAxnsGoOfqz6F16Dqmo9U2oj8HVjUE/NjtA/9e98ZPxvCDAAAAAElFTkSu\nQmCC\n",
      "text/latex": [
       "$$21.5443823618587$$"
      ],
      "text/plain": [
       "21.5443823618587"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N(y.subs(x, 1.5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `subs` function can of course also be used to substitute Symbols and expressions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFIAAAAbBAMAAAAdVcUMAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nMqvFy5UvAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABm0lEQVQ4EY2TO0gDQRCG/8vrEu9OToSUkkKw\nja/OQuEQESRBCBZpUlppLGwEIY1ip4gIPgorQUSwSRWEFNYmpZXGRgsFY2OhgXP25nY1IZGbYmfn\n/7/sIzsHBIryZDUQB8Punw5GxmzrIyB5pn0FI4F4KygZKwYlywRqKRr+iZBNZihLw2A3SsuN16X+\nRJNLXAEzUvmb72Coy94C1tzOFK+roLh/8DfgSIpGEQnXbSImjqFCkofAu9ze3GM7qSgxkWSm+kti\nnpF1Slp+6ZQrSVK1WtVdiiyQY2+M0oUdaXaSfd+o3K+NDJA+zN4yYO4jmu4kYw2rZNibQt5m7xiI\ntuA9luE4sweO0/AMsWUY9B8Aj54AIhNp1OpcqXPqdD48oCBkn6Tda9fYFQqFIreg2ViE10Hn7NGN\naiVMxO020spCt80WvIfyb0RNEimGVgz+nVwzWSk/Qy/gRMh59mhp8+VmaKOdzLjuJ8IpvAp5gb3u\nr8kej1qBs9d5yjD5uKoWE+oQjlE/90zUdRxdO1maIqultJQoe4f3dZD9A6SlVff4q7eXAAAAAElF\nTkSuQmCC\n",
      "text/latex": [
       "$$\\left(a + 2 \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "         2\n",
       "(a + 2⋅π) "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.subs(x, a+pi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also combine numerical evolution of expressions with NumPy arrays:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x_vec = numpy.arange(0, 10, 0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "y_vec = numpy.array([N(((x + pi)**2).subs(x, xx)) for xx in x_vec])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH3FJREFUeJzt3XmYFNW5x/HvG5TtYkTkBlEwoAEBFRWVaCLSLiG4gXoT\nQU0kuEbcTYhgEh1vogExCuo1ahTEDUVERYIIKM0iIoooIKAQg4KRASGYQFgG571/nALGCczS09PV\ny+/zPPOkuqaq+k0/zo/Tp06dY+6OiIjkl2/EXYCIiKSfwl1EJA8p3EVE8pDCXUQkDyncRUTykMJd\nRCQPVRjuZjbczIrNbEGZfZ3NbI6ZzTOzt83s2DK/G2hmS81siZl1q83CRURk9ypruY8Aupfbdyfw\nW3c/Crgleo2ZdQB6AR2icx4wM30zEBGJQYXh6+4zgH+U2/05sHe03Rj4LNruCYxy9xJ3Xw4sAzqn\nr1QREamqPVI4ZwAw08zuIvzjcHy0f39gdpnjVgIH1Kw8ERFJRSrdJo8C17r7gcANwPAKjtXcBiIi\nMUil5d7Z3U+NtscAj0TbnwEtyxzXgp1dNjuYmQJfRCQF7m5VPTaVlvsyM+sabZ8MfBRtjwN6m1ld\nM2s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vYEu7j4cwj0sd/8y5rLi\n8k9CI6hhNFCjIfBZvCVljrvPAP5RbncPYGS0PRI4u6JrZDLc9YDTLkQtlKOAt+KtJFb3AP2B0rgL\niVlrYI2ZjTCzd83sz2bWMO6i4uDu64A/Ap8SRt6td/cp8VYVu2buXhxtFwPNKjo4k+Fe6F+3/4OZ\nNQLGANdFLfiCY2ZnAqvdfR4F3GqP7AF0Ah5w907ARir56p2vzOxg4HqgFeFbbSMzuzDWorJItBB1\nhZmayXD/DGhZ5nVLQuu9IJnZnsDzwJPu/mLc9cToe0APM/sbMAo42cwej7mmuKwEVrr729HrMYSw\nL0THALPcfa27bwPGEv5bKWTFZrYfgJk1B1ZXdHAmw/0doI2ZtTKzukAvYFwG3z9rmJkBjwKL3H1o\n3PXEyd1vdveW7t6acMPsdXe/KO664uDuq4AVZtY22nUq8EGMJcVpCXCcmTWI/l5OJdxwL2TjgD7R\ndh+gwkZhWh9iqogecPqa7wM/Aeab2bxo30B3nxhjTdmi0LvvrgGeihpAfwX6xlxPLNz9/egb3DuE\nezHvAg/HW1XmmNkooCvQ1MxWALcAg4DRZnYJsBw4r8Jr6CEmEZH8o2X2RETykMJdRCQPKdxFRPKQ\nwl1EJA8p3EVE8pDCXUQkDyncRUTykMJdRCQP/T/cPlKeA8EXggAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1093af4d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(x_vec, y_vec);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, this kind of numerical evolution can be very slow, and there is a much more efficient way to do it: Use the function `lambdify` to \"compile\" a Sympy expression into a function that is much more efficient to evaluate numerically:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "f = lambdify([x], (x + pi)**2, 'numpy')  # the first argument is a list of variables that\n",
    "                                         # f will be a function of: in this case only x -> f(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "y_vec = f(x_vec)  # now we can directly pass a numpy array and f(x) is efficiently evaluated"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The speedup when using \"lambdified\" functions instead of direct numerical evaluation can be significant, often several orders of magnitude. Even in this simple example we get a significant speed up:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 loops, best of 3: 28.2 ms per loop\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "\n",
    "y_vec = numpy.array([N(((x + pi)**2).subs(x, xx)) for xx in x_vec])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The slowest run took 8.86 times longer than the fastest. This could mean that an intermediate result is being cached \n",
      "100000 loops, best of 3: 2.93 µs per loop\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "\n",
    "y_vec = f(x_vec)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Algebraic manipulations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One of the main uses of an CAS is to perform algebraic manipulations of expressions. For example, we might want to expand a product, factor an expression, or simply an expression. The functions for doing these basic operations in SymPy are demonstrated in this section."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Expand and factor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first steps in an algebraic manipulation "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMEAAA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Px+KY9BOXVCTC4PeA+HUknuS8aRZmPssWdLxf31F/wED/Kt4r5jyqgAAAABJRU5E\nrkJggg==\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x+1)*(x+2)*(x+3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKsAAAAWBAMAAABNknGBAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACJUlEQVQ4EZWSMWgUQRSG/7277K53u7klAcHm\nsomQLigStAlhG7E9LKyEXFaw8vA67SJ2dkEQPWNxgpVVUkt0K9sEDhEL5VKa6i4Y9IJwzu7M251x\nMxvd4s2b9733z9s3A/Av7HvCyy/tXT3LZ8sRt+Nuy3vZN4Pyprz/D99tWUNduh04P3TszLi+W7tZ\nOT6zXJfQiHQEqI70rJiUnhZw2y+AxSg3hLuLEVW0yfmn1QzvZXnOSebH3oWmS/dv7auITeWARRLz\nNwGMZ/hC0UZU+cn9qs/XXdS2Bb2F2yqb7bNhJ0ZkxAsV1vbxjsJ2YMUNsE/QqexNOS/f7igMKMV3\nmBgOYkuya0EWc8I7YidobZDC6clEvGmqLJR9zwtnLl5f9FMNOrT+KvwEnM6kbo2F5ZshL6Yzxx+X\nmmzCLeuxvZmTnXuO6Z6GSbLn8dB/osga4w4OAdMzR9UgLzuCe6Bhkuw67ntvVNmJh28eDJyjG2dn\ndLsvvne7l4H6I1jHGibJethKRLNC/AI22BRQ9/lx3IoRsblY7MmdyiRZ4IiKabZsJhsdFtyLiMSr\noOUB61bDZFnnNxWT7GrSbdW7hJJHLJV12GwHGibJvi4NMc+LSXaPzRZY633AjUyVusVVNHo6lr7b\nqZPasBL/MftIttwy2EuYXZj5LIBCza8rWuaujq8hNsaV+aUHSVkmi3Y/EiFpoUOlUOoWsbTbNFtx\njEDZKpsiBgX+AfzFj7EIR0Y4AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} + 6 x^{2} + 11 x + 6$$"
      ],
      "text/plain": [
       " 3      2           \n",
       "x  + 6⋅x  + 11⋅x + 6"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((x+1)*(x+2)*(x+3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `expand` function takes a number of keywords arguments which we can tell the functions what kind of expansions we want to have performed. For example, to expand trigonometric expressions, use the `trig=True` keyword argument:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAUBAMAAAD7IecQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUZs0Qu91E7yKJ\nmaurDqYVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlklEQVQoFX2TTyiDYRzHv8s8tt45UE5qe8sN\nk1yIg7VSDg6jXpHwXrRSuJAiWhxcd5QcpISknMxFuTiudpELmbVcXLBFQ+b3vH/2PO82nnre5/v7\nPp/3eX+/Z78BZUMJlRl26D4zlWvfdoCEkEJFj0g/m7HrW/gTQkpqivSMFJvSnZKtGtWKcrT67MDy\nAI+VmWnYsPedYrZnmEqDuUfPi5LiwoZ9MR6Nw9USjiR+0HTa2KGSEeTuZbJV52sJrs0EO4F7RIEY\nKP8tVfmi7UWa3hNMc1TAC6OMNgewo0PFOrAC5Gl7k+ZsCLccFXC/DrqwHng+2sDhJeCNto9pPujY\noMWnaWMHmpYmeQNGcADsupji8LKAD8FeiaBhFzgJL11eAOdwFySY0qBDal6ccB71dHnb6AKyEkwF\nshzqIn2Okwu8DiqwV8cqz8FKI0nQCAbTVw44izWK77AbHor7i0/+4mP3Z5p/Cphvb87EHfBcMETx\nsOFJj+o/twEoMYkzpLORmNwplY1EBfw1Klu0evMb71c55r+/1S+z8V/W/OfTdQAAAABJRU5ErkJg\ngg==\n",
      "text/latex": [
       "$$\\sin{\\left (a + b \\right )}$$"
      ],
      "text/plain": [
       "sin(a + b)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sin(a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAAUBAMAAACwpfa4AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUZs0Qu91E7yKJ\nmaurDqYVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEMElEQVRIDXWWX2gcVRTGv+nuzOxmNt21ImiE\nZoj6oCayiKDoQ5aCINTiKkTwX7s+lIK23SVYhBbtog+CFV3wRYqQqiUqpTJCMaVQXYOFljaypooP\nRlxDEUSkidWUaJv4nTszd26WyYU7893zO2fu2XPPzi7QO06EhmzQC8J1iNejOsarKLlVG9aIiCLG\n1ocJ9hqR/iOxGYp41ydcp9EBP3GcgrO/CWxM/xhTkWOMrWtJpB2H7ExshhK8nes0OthOHJ8B7C7g\nVBOToUjVSMPbYr+CHyvzLvgKp6b3mlTrbAcolrmc1iZDCA1HCj4UM+dIrMw7cX6JBk3TE8gFwESN\nfi+YwbEW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64Qr0f107yKklu1YY2IqPwl+x/SgSmeCF1yWAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\sin{\\left (a \\right )} \\cos{\\left (b \\right )} + \\sin{\\left (b \\right )} \\cos{\\left (a \\right )}$$"
      ],
      "text/plain": [
       "sin(a)⋅cos(b) + sin(b)⋅cos(a)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(sin(a+b), trig=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "See `help(expand)` for a detailed explanation of the various types of expansions the `expand` functions can perform."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The opposite a product expansion is of course factoring. The factor an expression in SymPy use the `factor` function: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMEAAAAUBAMAAADGn0QzAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACtklEQVQ4EY2Vv2tTURTHv+/l10vyUmOlDrqk\nRZ2jf4B94sNBUIKlkxReQVERMQ6lg5XGRReHgi6KQybFyYCKQ4U+QSwihdZF3Lo4G6SoQzCec38k\n75QX6h1uzj3nez/f3PN+AU4NI8akyY+PqMOt6opTG6VQiAOjqqhogFNPU0zMnAS2dCUV4ay+amnE\nqbT98J4CfqBKWfNPhc7fxFobH3QuFTEB76dCuI3kTq+pVxtzPQreqsXRpAD39aoSo7iCspJLhFUs\nt/BLIfLiH1oHFNjhk6LNpzkUI1T+wl/hmkRYhxdtf0chDor90iHbpqITCYU5Q7bHDjjLNYmwDuAu\ngRALJFm/c+i2bo90yDWoWKDJX9x6rls23I88HXOWHSRiqPjYAQhxgvZ33Cv5gLWQDm5AqUwN+Ixj\nzUsU0zBnoOglAY5wSiIGisOXY8ANcBUox+WeVyXpbgcvolS+BbzDWnyXYhpDhxu0uscpiRgqyk8I\nGIFmH9k6K8theOZRGG5yrK70WJeiYhuIcZqTeB2G18LwnIpVC39wmEAIBR7HIASVgX1NnmnILg0c\ngN+6njgDdx/WIYGwZ9gPTLfYgY5Iwm2eaUiHUkQp7hLG6L7Rw3bJa4AYzzgpEdahH7MDIegyefEy\nCrECSAc3oCRf6QeFLpYopmEdvgO3hlc6gbCKh8DNKtwAb+imaE1jnHfvPkOuQ6lyA6U/ma5To5iG\ncXCur85FwEVOSYRVTMGj1hKCzrmxuH6hxtKhQ+7bzhd6XLYpRef0vy4tTHGZhnHI9vv9CDjPKYmw\nitLsTFsh5CM/6BLvNA/rvIrtZLuk1k7EPxJhHZSAEfK15Vd1Qc9pb773SUHqm08oGHE8uUXE5u2d\nEa5CYd7eeyBSPx+KY9BOXVCTC4PeA+HUknuS8aRZmPssWdLxf31F/wED/Kt4r5jyqgAAAABJRU5E\nrkJggg==\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(x**3 + 6 * x**2 + 11*x + 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Simplify"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `simplify` tries to simplify an expression into a nice looking expression, using various techniques. More specific alternatives to the `simplify` functions also exists: `trigsimp`, `powsimp`, `logcombine`, etc. \n",
    "\n",
    "The basic usages of these functions are as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0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uUXE5u2d\nEa5CYd7eeyBSPx+KY9BOXVCTC4PeA+HUknuS8aRZmPssWdLxf31F/wED/Kt4r5jyqgAAAABJRU5E\nrkJggg==\n",
      "text/latex": [
       "$$\\left(x + 1\\right) \\left(x + 2\\right) \\left(x + 3\\right)$$"
      ],
      "text/plain": [
       "(x + 1)⋅(x + 2)⋅(x + 3)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simplify expands a product\n",
    "simplify((x+1)*(x+2)*(x+3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAPBAMAAAArJJMAAAAAHlBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAACGjDitAAAACXRSTlMAVO8Qq5l2zWYZcMvdAAAACXBIWXMAAA7EAAAOxAGV\nKw4bAAAAHUlEQVQIHWNgAANGZQYGk5DJQDYbqQSr03QPsBkAJYgIYEZbtZEAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# simplify uses trigonometric identities\n",
    "simplify(sin(a)**2 + cos(a)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD4AAAAvBAMAAABJZWRJAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWZE3Yki\nMrsGmOkjAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABaElEQVQ4EWNgIA0IGeBTz+zqj1eegSF/VB5f\nABIKnxD9kga8+kec5H/8YDCGxwmoo3qwO47nAVSc5QCIwQnlwSn2A1AmcwGIYQrlwalWOGsbiIXg\nQsXXwOWNgCzGr3AuhMGzAC7APoGBoeWXiwBDW3YCw3XVaykJQCm2AAYG5jSfaUDDWYFMhqVAM9Yw\nhDAwrEvg+QPk8zUwMFgzdCUsZ2DgADkQJK/LMN+A4REDww8gn0uAgWEzw34DGaD4Aog8A292/AGG\n5wwM34B8pgkMDAYMdUAWA+8HiDxz3YH7FxjeIeQhLJh8At8ChvuXDaDyIPMZeP+C9HMuABIlDAH8\nGxjkb16AyoPcJ8z2gSEZ6r4ohgCmBwz7b8D0cwcwcH7k+8ADVMa6AaifxfsAj2u2WdmV/75ynxzA\nhjK7Jad2AKXYLwAJDIAI31MYciABRISA4wdDDd8BqBAkfjHk4ekDrhBNyQkoH5S+AKXTe9mWCL8r\nAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{1}{\\tan{\\left (x \\right )}}$$"
      ],
      "text/plain": [
       "  1   \n",
       "──────\n",
       "tan(x)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(cos(x)/sin(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### apart and together"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To manipulate symbolic expressions of fractions, we can use the `apart` and `together` functions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "f1 = 1/((a+1)*(a+2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiu91E\niTJVJ+QZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB/klEQVRIDe2UP0gjQRjF37pu/phEjgMLK0EL\nz1NwCekT7lAEC1OohSCGAzvlUohBLJJWbLbQ5mzs7k91gtgqtjY2sVPS2ikWFnca38xs3Gwcs0UQ\nhGSamfm+37z55u3MAm/ePtqtbWFOzLSoAHzvKMiP0PFB3cV34MPs+FqptYfRWd1mDlRbbW3mV7Pj\nRkuvZbdUIhD48ZoAuh2Z0gLRuT+VGrChVTCGADMvU1oghcR/F4hk6xWMnJqlZu84uBATPfAVGHSB\nmCpVLURNASGhkBRRPTAKzFQUsOeuVZ1fIXzCqB4o2kJBAsuEoovzPLZofgVLnFAA2C1/s0XvAcCx\nDQn8YvjUCd/IvAfIU0TyjAogPoJiA4D4Az0SwAE9/wRrn0M2fw3GX4YIIFnCgkjXAYhlOBPAGGDd\nIZbjMFEobA4XCsxAOdl7wxEBLNk4YlcPYI6BGtC1j3SFczZ/DTUAn2E+NgJZBiTAItPnGFD5BoW4\newrzAYYoh+15iz5EHUiARqU/4Kfh+AGfk+YtevL9PqA3i5CjnCwD4VzkMCHz3hZSwTpnlADWsZ0R\nY6+GvcvyNB0UwTN+i8mrnRWZf1awvtxPUbrCKAGkVq8nT9h7CsVq9Z8L6C+tpNV1DAT8D8dUdigB\n3cvSAPjt4i8793UHAtofiJTrUQUFAoE/sebAE+USwojXIqQHAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{1}{\\left(a + 1\\right) \\left(a + 2\\right)}$$"
      ],
      "text/plain": [
       "       1       \n",
       "───────────────\n",
       "(a + 1)⋅(a + 2)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI4AAAAsBAMAAABBB53eAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMlTvq5l2ZiKJ\nRLuWvIZ2AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABsElEQVRIDWNgoCEIEyDGcNZE/KoYK+qJMUe8\n/SN+cxgY5hNjDgPnqDl4A3I0fPAGD/3ST3u++gL8TgHJcpR9qiKsarCrYJ1AHReOmoM/HAmGj5Ax\nCKgwMPzHDj4AzedRUlJOUlIqADL5sav6j98VCFmC7kEoxcsaNQdL8OzoewITpSR8GAsYzl+AGsS4\nAWYiJo2zoo+EqGUXYGBLwNQGF4Eqw13RQxWwGTCwf4HrwmRAleEuqKEKmD6SZQ53Tye0RQOziIGB\nGbNNsePENAGI22DK0CrWaxuYPqAqYGC4fwDdO7zZDPpQMezmMGYxcDyAqIApYGAwRzeGQWwBQx9e\nczg+MjBPAKo4pKRkpqSkDlbL0QDVgqD6BRgsQTwkZaj+YnvAIO8AUQ93zwwIH5nMY2CExSFMGao5\n8gcY4qEaYApYGxh2I5sBZDP+YWCFhiIDTBmaOQEMj1g3gLXBFHgwMMxGN+crA59CNEQQpgzVHKYJ\nXOY8KAq4bc60G6CZw6DJsLjgAIoytHTIWHlk+1wUBUzAMhTDHPE53pUXUJThruhhDoYox0kSVCaN\nUyuKBLIyAOpdmg617KB4AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- \\frac{1}{a + 2} + \\frac{1}{a + 1}$$"
      ],
      "text/plain": [
       "    1       1  \n",
       "- ───── + ─────\n",
       "  a + 2   a + 1"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apart(f1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "f2 = 1/(a+2) + 1/(a+3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHwAAAAsBAMAAABVvsF6AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiiUS7\n3TIuwQ1sAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB30lEQVRIDe2Wv0sCYRzGHzs0zx8ZQUGTUENF\nRRIuTSdF0RIKaUMESWMNNUQ3hf4DwQ21BIEEEQRFBO01NdQQEQ0tubYpDpFR9nrv+173+l4m1NDg\nDfe+3+d5Pu99+eqhwJ9dHZFGjnL1OqaUyXgjeDRZcsSB1UZweJq4PL/m6OSZiMp3X5vkyHpWTDpV\n7vGXaSf9H2qu9K+aauJ1xldxvgoE8en6Zp+ux8g25Jyq1Dm4ajUn/8OAauzdo0uu1BmdmrrJ85h9\nVRMIZ5mgGHZH2EfhexOELlp5igjdCoZQ8IYmgB7BYLh/ENqaYAgFx4eBeN7uMJxIVvN2m+05nomY\nuDo/x36xLVx5lLGdg6WIqXKcFE9EOTNaCzTNcfV4VsL9A8hQ8Qv3lwGlH+4LEQf2T2v50SwWavFg\nDHCXEEwT41DX73R9nUZapD8gixE8EM/2EgIpIrRcQMtTiDWvGggUqfJ1H4LyQSureU+CCFoOYZZi\neKgk40oZLjYhC+8EeZDWjiuXYR7AcNJP8JWdyBeliMBat1lxvC0Bj4HWtPfeR1MM92YRTnOOrxvY\niuXMguN7RwczZPJTJ9srNMRwnKeuOWWt0eXnKfpxcDxTqbxbdnXDcUGUCo5LxpikOAnCS/gJnQmX\nnOfh0q8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{1}{a + 3} + \\frac{1}{a + 2}$$"
      ],
      "text/plain": [
       "  1       1  \n",
       "───── + ─────\n",
       "a + 3   a + 2"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACs0lEQVRIDe2WzWsTQRjGn02y+dpuSCMo9LQk\nYC9KK3pS0OhfsKdCvSQIXrRgiGIugrnWi5YiWAsSPNSDivVqhKQFUU9G/wHr1UPpwdDi1/rOzs42\n231NFkoPgnPYd/eZ3zz77uzMvguEW6F0KiwCxpvEcU4Pa3oVt5thGRnHqTEyIyVtZO4N6GZXXhg3\n1wbUYaeZFpLfBgDlkBzQhp8a/f06kH+2D23y2H15Jz+HzfWyVCIc79Ywnze2JKkc4ra2E2GsRFag\nP0JsOuhAV6ejOsQsxPrIdolPtduvltvtqhw6lZdx5HEdyEyjUpageoqr4NcJY2daGK/U8NnrUg7L\nwJTN4Ix0AVir9HDGlDkrBwt4ytCMpD1pHG0Z3dxKSnYqhwJyCwzOSIbjOC197sbhd0EHbfJSxIfY\na6py2KtHv9ajvsLolv/JA5oBWj77aweU179oq238LesvsmMkcIgz0Iony0jKPcUDjes9BbzkHGaQ\n2oG+6naxQAHmbw/IWYMO6mNwGVgCbokuHvjQw3cPyAa2v3J4CFwrY1Y48MB8U/8BCUwIym/KoWML\nB6NJHTwA8RQSoOLAFEkSX9ig0gMIAIX6e1tEqFsAF2uQwFmSw0USSG/TFIipFEB6AR0K1HyHI4/J\n0gWegy+S2SrhLRpDAGY3UKJAzXdA6oEHUGSLZJHwxBYdCBDF6hmFYBVdsn2AKZIYs2iE77AI3fut\nUTmMA+d6EqAkmSKJT9DySLfIhgB9G6ZIh5pycGzh4AI0UUyRTFgYy/szqf9CfPVjwGGRXpYH1Omt\nhovkRKN+hSaoRqMIwGt8rYrz3Rw2Yf70gDuUZLhIdhyHFq1RpjEEYObt+bkmxV2HdLFEggvwi9al\n5XIcCQQ3TrBIMjuLAXBC3o85ert7JMB+QFy/eN4NI4GRH7HhwB+u8vuFvy0h3AAAAABJRU5ErkJg\ngg==\n",
      "text/latex": [
       "$$\\frac{2 a + 5}{\\left(a + 2\\right) \\left(a + 3\\right)}$$"
      ],
      "text/plain": [
       "    2⋅a + 5    \n",
       "───────────────\n",
       "(a + 2)⋅(a + 3)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "together(f2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Simplify usually combines fractions but does not factor: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAvBAMAAADdrw/+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACs0lEQVRIDe2WzWsTQRjGn02y+dpuSCMo9LQk\nYC9KK3pS0OhfsKdCvSQIXrRgiGIugrnWi5YiWAsSPNSDivVqhKQFUU9G/wHr1UPpwdDi1/rOzs42\n231NFkoPgnPYd/eZ3zz77uzMvguEW6F0KiwCxpvEcU4Pa3oVt5thGRnHqTEyIyVtZO4N6GZXXhg3\n1wbUYaeZFpLfBgDlkBzQhp8a/f06kH+2D23y2H15Jz+HzfWyVCIc79Ywnze2JKkc4ra2E2GsRFag\nP0JsOuhAV6ejOsQsxPrIdolPtduvltvtqhw6lZdx5HEdyEyjUpageoqr4NcJY2daGK/U8NnrUg7L\nwJTN4Ix0AVir9HDGlDkrBwt4ytCMpD1pHG0Z3dxKSnYqhwJyCwzOSIbjOC197sbhd0EHbfJSxIfY\na6py2KtHv9ajvsLolv/JA5oBWj77aweU179oq238LesvsmMkcIgz0Iony0jKPcUDjes9BbzkHGaQ\n2oG+6naxQAHmbw/IWYMO6mNwGVgCbokuHvjQw3cPyAa2v3J4CFwrY1Y48MB8U/8BCUwIym/KoWML\nB6NJHTwA8RQSoOLAFEkSX9ig0gMIAIX6e1tEqFsAF2uQwFmSw0USSG/TFIipFEB6AR0K1HyHI4/J\n0gWegy+S2SrhLRpDAGY3UKJAzXdA6oEHUGSLZJHwxBYdCBDF6hmFYBVdsn2AKZIYs2iE77AI3fut\nUTmMA+d6EqAkmSKJT9DySLfIhgB9G6ZIh5pycGzh4AI0UUyRTFgYy/szqf9CfPVjwGGRXpYH1Omt\nhovkRKN+hSaoRqMIwGt8rYrz3Rw2Yf70gDuUZLhIdhyHFq1RpjEEYObt+bkmxV2HdLFEggvwi9al\n5XIcCQQ3TrBIMjuLAXBC3o85ert7JMB+QFy/eN4NI4GRH7HhwB+u8vuFvy0h3AAAAABJRU5ErkJg\ngg==\n",
      "text/latex": [
       "$$\\frac{2 a + 5}{\\left(a + 2\\right) \\left(a + 3\\right)}$$"
      ],
      "text/plain": [
       "    2⋅a + 5    \n",
       "───────────────\n",
       "(a + 2)⋅(a + 3)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(f2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to algebraic manipulations, the other main use of CAS is to do calculus, like derivatives and integrals of algebraic expressions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Differentiation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Differentiation is usually simple. Use the `diff` function. The first argument is the expression to take the derivative of, and the second argument is the symbol by which to take the derivative:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAbBAMAAAAt2dQtAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABYElEQVQoFY2SMUjEQBBFf+4kiSTGqGBhlUKw\nVcFO8IQUIihyYGWTTu1iIRaiXqWW1tpY2Qhq4VU2EQ6usrDWwtJG1FYCcXZn4xI8kptidubvY3aW\nGaDK2nNJFQLHH2pUQqbvfVdDl8ZPJQTYaR+QGfcBtYkxAnK9reaTXlsjN9YbkOoz+WvcAIslUAfw\nlk7nuZrmTnRIkRNjMMu+YIp3tRUh94xvxjUgoiKEZb7dpaN7MLEfc6ogKyOjb62zOgu4d7VNs1GA\nHt53pkZImWR1i9pLnNRWrXElr+X4h+L+mKFzqoSBaZnch+F2GK6IuI5XcXwKBxAEDKuOdOMfiMSF\ngug5it+EF5b/rgk5+ytWqXE7OYKVcKogN4XcItU4zfi2tYBRZvJKVoQLoWywTAWf9rrNgLMcqgd4\nEcoqy6VjMSKG5LpwKPyjDimiAbPNFORi0snTsqX7K2AEOf7vlOtL6i9nYkLvuMXjdgAAAABJRU5E\nrkJggg==\n",
      "text/latex": [
       "$$\\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "       2\n",
       "(x + π) "
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAbBAMAAAAKd1XFAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMpndu3bvImbNiRBU\nq0Qb3U6NAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABl0lEQVQ4EZWTvUvDUBTFTz9CY1swOCsWpyII\nHdTJoZtuVkEEQXRwUpCABTtJFgc3BUUyKEHsoCBkSUVBKIijoyhKJ/8AHUSEivXel5eWp1XjGU7u\nue+X5D7yAoRVecANiyJqRfPhYUd/Dg0D0fw/4IoRHtZ2wrPqGAnrxzt1k5ci7+xdbCgKb2+3QMVI\nvPHioCB223OiewbETH2Jam2BG3qGvamrZsVFsoBI+YSHKW1zjom5uBJS4dS8bMMR8EoQ/asKY1+u\n6qaAJyl6s2szBQXWGqQM0CdhDwIeA1KOPhTbVODj7un1VepsSNjx4RHahpusp+Xo/hiRatKcYO7S\nh9OGDy/Tk9GRF80j2x627T2u43jgSy8bcI4mDHTKiYFggz3IMSXh61rt9YYijUE9g50VwFnUOT6y\nCYmPQhtMu3PQXL8n4VQdH9wINgi8cDwAnqrjKHFNkrCWwyLHfjbWYeOOnF50MeVlLe6QJBy3cM9x\ni62lXz93QuyyBX85SKetFaroIKkaVaOS6IiqKqpRSd8e9OdvBXwCt6VWuiSpHUoAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$4 \\left(x + \\pi\\right)^{3}$$"
      ],
      "text/plain": [
       "         3\n",
       "4⋅(x + π) "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For higher order derivatives we can do:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAbBAMAAACekfw3AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiuzKJ\nRN0MreaOAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAByElEQVQ4EZWTPUjDYBCG3/6bNqmKKOgi6OCm\nQToKFgV/Fi2oi5NQFFy0W8HBdhF0kY5OtaM41cnRgigUBTs5d1I6iBVRB3/i3Zd8bVO1knfId/fe\nPbkcfAGcSF1ecNJOvUVMOyQqOMs4Qx5wWHJGAP26U+LOKaDGmomDZqOe73G4I3Nl6TjPsZKTzs/T\nmwG0gkZ9rkEgAvWTewLk/iVPAjjt7NMRWXwGJoEB7qwNFZhrRRzycQmMGAZlfiKGgXkah4qsirOJ\nGJVFJlK6IJSyNH8jAiWrygTpUadxMcCzNntL81lyxqZhGC+Aj6pCJqF9UBJMA2PYX7k3KxahXvUc\nrGeAtoRpiz2AcJTScAdwjhu910acoOjPk+Mqm7ZFLHHmLgE6tkRBTSa3h5LJKCc5r07PUJVjkvgq\n3sAkgFcOWXKPUDTMqZ3ohpIxvwqhdy6zJOFLt/MMrcwmiWeEYvATwZt3+auIi0KNGNfbS+TYNs9e\nX8yRRzdTewpWFQJZcsYG3AVKffwg+SbeZpAyjC+Kaa5nKr66Kwp14gjeAlmBvOU3Hi1vSbaxU8b2\nm+ih1Rpk3YQGh8KgvcdW5Nv+U63+qD/e9t9fS0O+AbbpaS6aluDxAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$12 \\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "          2\n",
       "12⋅(x + π) "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAbBAMAAACekfw3AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWYiuzKJ\nRN0MreaOAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAByElEQVQ4EZWTPUjDYBCG3/6bNqmKKOgi6OCm\nQToKFgV/Fi2oi5NQFFy0W8HBdhF0kY5OtaM41cnRgigUBTs5d1I6iBVRB3/i3Zd8bVO1knfId/fe\nPbkcfAGcSF1ecNJOvUVMOyQqOMs4Qx5wWHJGAP26U+LOKaDGmomDZqOe73G4I3Nl6TjPsZKTzs/T\nmwG0gkZ9rkEgAvWTewLk/iVPAjjt7NMRWXwGJoEB7qwNFZhrRRzycQmMGAZlfiKGgXkah4qsirOJ\nGJVFJlK6IJSyNH8jAiWrygTpUadxMcCzNntL81lyxqZhGC+Aj6pCJqF9UBJMA2PYX7k3KxahXvUc\nrGeAtoRpiz2AcJTScAdwjhu910acoOjPk+Mqm7ZFLHHmLgE6tkRBTSa3h5LJKCc5r07PUJVjkvgq\n3sAkgFcOWXKPUDTMqZ3ohpIxvwqhdy6zJOFLt/MMrcwmiWeEYvATwZt3+auIi0KNGNfbS+TYNs9e\nX8yRRzdTewpWFQJZcsYG3AVKffwg+SbeZpAyjC+Kaa5nKr66Kwp14gjeAlmBvOU3Hi1vSbaxU8b2\nm+ih1Rpk3YQGh8KgvcdW5Nv+U63+qD/e9t9fS0O+AbbpaS6aluDxAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$12 \\left(x + \\pi\\right)^{2}$$"
      ],
      "text/plain": [
       "          2\n",
       "12⋅(x + π) "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(y**2, x, 2) # same as above"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To calculate the derivative of a multivariate expression, we can do:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x, y, z = symbols(\"x,y,z\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "f = sin(x*y) + cos(y*z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\frac{d^3f}{dxdy^2}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAAUBAMAAABSee3BAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnarIkSJZlS7\nme8N5bApAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADlElEQVRIDYVWXYhMYRh+zszsnvnbcVKrlJiG\ncOFiIzY/F5twpz0ulqRhifyUGrkg7DYlF27sUBsuZCKJUiPJjdjkpySmDUVkibhRu7V+1t943u/8\nzJzv7PLUO/u+z/d8z3vOe77ZM0AIB0JMkDDLjfXFxuIfecA1WQAkQjAHQlSQOBQom3WPnld3XUHs\nQ12puW7nioSOiO6mC+YECCMbKGF042zRoWJj9SXNdTJXJHRc0QmtTlaDRL9bpmyVNFvIDAUVUmmu\nCYoldLTrhFZHC0Fiulu6zTNtaB4NKqTSXI0hQEKD2aYRerlXIyJFh3CbR0b85uYKXxpyncslCQdG\n1/YjMsGmKq9J5a3PYL5l8eJMBVO7TiG24UKWgjyjde3+9baRt9FroYUbBG5zZtERKPGhr1j+eeVa\nm1TI9TVJCQdTcd6ezzRdBpy8dAtNw0BvJfYx1o60PQ1oo+Ahr6eUXBjNJlJD2MSvTJYkUW/eVwKU\neDawzDa/cTHkeo6khIPjOGvdYBqtACo3K4NIDwA5pEajJcRGj1mwKVjKo2IlRlKFgy1ZPGJTuSKi\n3nwRKyW+DzwGfrAMuV4jeQ2TFwhmwcI81kCmCCc38AGTbBi/SXbyisaiv9aJ4BPvHJEBqjI2vnDA\nwyQTudzMd7lcN1PnOSgxm9+BaEKu6CQp4UFEjszZEB9BZwfiQt8uAr+ME7UqczaHXBXQZ8V4rlVz\nVv6dy6GAErM5R+M1b3TVm4sRIQPijPnBqW6ki3fnv/cg+Z00x86L7uDHIJqGgHgbU8JrnqpiH6DE\n9ea6Kw5zh4SDqzxca5jK0XDydDe4m88cqUwV8e/XgV2seeBS1iY0WVylJHTgVgN8PEpcbx5ylcMm\noRD/mR42y0wT7OPkLQNxOSu9ZZyMvUekdMvCA9ZnOO/KE/BF8Qp93NFSIkm4d24uPv2cs1Biztwd\ne8j1BXdIKBjb1uQvS8YpurmxM/+NhLF7fQE9p3fg6IVLRdYc1pSu1pdl/ul/UwAiHVBwm0dqtRqb\ni3hVbfOq2tabf7rHcZ3FPRIa2us1n3oYjf9eB7ns/cdzm4c3KEZzNXl9EjqueMQWzCh6ecNf/8XS\nnDXkAPa7awanMDE014leLGnPZAnujWsmD14QLadtPpUs0/9Dc53oleq/9o/kO8Y19X5MxLuect13\nHVfrk5qr3IB3E75GksAPnsCKU6gvhc9f9LN/JwHXJKfL+AuGGQ+nZudVwQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- x \\left(x y \\cos{\\left (x y \\right )} + 2 \\sin{\\left (x y \\right )}\\right)$$"
      ],
      "text/plain": [
       "-x⋅(x⋅y⋅cos(x⋅y) + 2⋅sin(x⋅y))"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(f, x, 1, y, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Integration is done in a similar fashion:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAUBAMAAAD4uit9AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUZs0Qu91E7yKJ\nmaurDqYVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACz0lEQVQ4EXVVX0hTURz+rtvu3bybWRD1pBcD\nH6rV6KHCoIYUBCqsh1ERxCWIIKRECqFBDCoifBk+SQSaYCARDJIMIRiDgihpBeKL0YoKwgKtSFaa\nfffsnvtnzQN35/t9v+/3nfu75547oHZMeokub1AX60kPHcxXA2XMJfU+FwNNtsLL+fGUL1yoRsqK\ny4Z8FmrKzdRHp3z0WV8kgh4/VbTDgOHnZRQsSSTmqOELrWDQz5y3w/UMw76GoI4Kvb7RcdGzDhQg\nlKvG6xk+9stxEsq2ztTUX2x+sGmXwWQDW1DbFoaKOPMG+j3E7JakoTo/k0Bv23NRR32c8riBaRPD\nE0oSeItzQBangZuG/ocCjWQvjho3UOhAwyKCKZIc0nA6odxXBqEZog64BEQDo9gNtT8+R90R3DZh\n4CpwBfhJIpwAnuGVeUBPzELrQyBLkkMaphFYChegLIk64BrwMJbCAFSIF24/wss7YBleBr6zsDEH\nmDjORjCGDQaURZLRdPrEeDpdJrvKsJWLrog6YILyRkOUbjGtHNSnayXLcMA1rKLIL7Q2Vw0ptO8w\nYi16iIsuizphiBFTWQIiZaZo+AjBisfQapkN8YeNbKcsS8hhGzp3uCrqRMuYRcMocFDohrEH+Ogx\ntDZlLzejHVrZoms3JU3vxhIiFVEnNoUyagMlNMHalA4TGatfu+UoxT+0RR75WF+EuxQrUMUhN2U6\niRfKXYQKog6YYW4OI0ls7e68RTyPO53duZa1zy1r7/f9LosW1Q/t8cN8/l/jfI9CzVRxSEP12848\nnrz8IurID/O6UHyXRyk4zkeLY7z8w3P0+BQhT4I09Iv5muUtZlbStQeNfI/MfcJFLlm0Q1UUypw7\n8+PQlFIrkogaEjmzJiuvo599p5zEOiCDcFIzZLLO58v5wA7Fm3kSpb2s+G+eQqTttcNmHOSCSRcC\nXd6gLq79C/gHf4qzfkFAyyAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x y \\right )} + \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "sin(x⋅y) + cos(y⋅z)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVAAAAA/BAMAAABEE43RAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGz0lEQVRoBc1aXWwUVRQ+szvb7s9sd8NfJEY7\nFFP8CbKpBIOJMi/GB02cQKL4k3QFBIkP7IMRfJAuYkQepDWKsVFkIUZ80Q4/CUEfujExGh/oiqYI\nCbGFqAmRpFAVAwKec+/89y7Lzmwnvcneuefce77zcWfunW9uAQhR5J4QwVGG9r0bZbbguWLXgsdG\nGjliRJoueLJ+LXhslJGJySizhciVvRwiOMrQzBXKJo2+Wg2RddV9DYJD4hN66m9WV6Q3G+S6Sbcy\n3qvfpBu7UqHwGXbqP7psBdjIzEBVtuHGEQ6fkeJEDwMM5QORpKB4oVFoOHyGzoni0u+tNMpWt78x\n0XD4DlEJ3069al0iDTqUR84VpDXdeuKTezdqOHbWCZDHPTHh8DkUm1H5H4CRoge7GSNuwPcaHIKO\n050ljCt+CbEJvG4cpLIHWyHxGRdOFGc0HN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jZPLPq+lFx33UF2iT1SdUcFbPqLyL5MqgQnkotS1dOUa66jO0ossMenK9hXbH4LM\n0i78M6B8cq32zNnP3t/y74H+3fHrrwwXmOgkNxserPIRNUFEcnEebFF3Wkd1ll5k40lXso/6zFF4\nUoPV+cQ4XNh3WbpEX3lHIFVgopO5g5GkKDFRgVyEF2BT/lPrqM7SiywxO8qj04fMGORK8DvgMdmH\n2LMccgUo4hJD4jHuZuMDVZzofHZMZL23hHIR8vARvubMozpLhlFOrisZ0QE8x1Oubd78IJCKHNL2\nTyR02gv6D2ncHYgjC/LOaO4GFvSL5CLAJewxRaObKNeVjKiBRNvZR8MeHNtRLJ5vY5sWik7uZjkD\nVV6iFoRILoJCRwBcNNp6kQLYjNaStRid3+KM0r8HiGh2m/ryPCIqo+h8nrmpK1gRExXJxX143r2A\n7iMd1XkWE+lKPVXIcqKwEz8oGVFlUhu5i4imSXQydzCSFCUmKpCLiSuZCbnERaOjF1li0pWQLVtE\nR0rwI7xDPTshOYBEDSY6mZuND1SJiQrkotSzYPFm+6jOWXeYlXQlwAPrlBWTPwyfA+nh7vxzN77C\njkUQKwF655LoJHcgijyoDlE/ousVSqJRLvsHTLvtI/pUAXwfJ5yBLUq4aBSIkulm6iNavKiMiVKi\nXOSFi0aRzBOFtdDnJSrPLccMETrKRV64aBToRVFUK31x75lOvBhXhfBuuQgivSiMaqHT9590knpH\ntYXoLYSSrnvAktVejz2DjE2qm0yi55jbnElt72qaA0dnEjk3F2mv7jKXJXA7n6El5v4z29PrZyhL\nojUnOm7/Aywn7A6s7fMGAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x \\cos{\\left (y z \\right )} + \\begin{cases} 0 & \\text{for}\\: y = 0 \\\\- \\frac{1}{y} \\cos{\\left (x y \\right )} & \\text{otherwise} \\end{cases}$$"
      ],
      "text/plain": [
       "             ⎛⎧    0       for y = 0⎞\n",
       "             ⎜⎪                     ⎟\n",
       "x⋅cos(y⋅z) + ⎜⎨-cos(x⋅y)            ⎟\n",
       "             ⎜⎪──────────  otherwise⎟\n",
       "             ⎝⎩    y                ⎠"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(f, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By providing limits for the integration variable we can evaluate definite integrals:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAUBAMAAADo9qfkAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABuElEQVQoFXWTP2hTURTGf695r3lNkxgUh2Z6\ntEMHHVIKTqUEurkkINihQlNBLBU0Zqngkk0MDgotpNWh3bqoFToUOjRmKYKF4CBEBLN1aIb+kxYR\n43dNW/NK8sE57/u+c7jv3Hfvgw6wai2FaAys/uFki3VOr5wzQ6bgNsETn3cqPvjMCbgHCz6vKaKe\nzwyWWIRHSZ/5T4Q0VQucl2ym2zbGW7oMXTfpfRqcwVyF8c9PsLfrq/LKijvXseYpFO0a9Eu7x0p9\nFfuVvUygdAuWpEcV2SrhPWekPCC+qwhllDaIHIWy2EfP05Sk3+rDVa4RSDhYCelvCrOqc6CUqsBx\n6PCjKEV5vOFSCcY0GSkIe3q6v5V+5OHQedowhhpxf5JK4mZETeMXrNj/FQ+uEjUHoFfTtcon+Gr6\nKGB7hGNmRiI9Hu7Jd3iogtlMIMMNIh7d4rvEZ3MzIn01Httz9GaraYakc4quhPuHmzv1FfFBNhuN\nXyLO3a0Yl2eneVbfyUsXjHe/vI8XfW30mqItmkeoKZuwltp2yTSX4gGT+dO6LkUnaNB3jJxVdc06\nQRf3RTl5VjX764CLv8JfPcJj8HGPsdwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$2 \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "2⋅cos(y⋅z)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(f, (x, -1, 1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and also improper integrals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB0AAAAVBAMAAABI7vhRAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAInarRM2ZVBDdiWbv\nuzJCz3LGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAr0lEQVQYGWNggADG/2DwAcplYHaAsSC0KCqX\nIR2VzzEBlc9WgMrvROUyrEblg7TrAx3wDSrMtIGBa12RtKIAkO8CxJwMDM8ZFjI9ADKZjgIJJSBm\nuMDcACQl9B0YGEC28xkAVQFB/wUG7gVAmm0DfwOQYmD7yMAJYvQ38DsAKQbGbwy7QLQmA88CEM1g\n3zADRN1mYF4AohneL08A0zCC9WgDjAmm2WGuhIkGwhhAGgDwdic2xV4k0wAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\sqrt{\\pi}$$"
      ],
      "text/plain": [
       "  ___\n",
       "╲╱ π "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(exp(-x**2), (x, -oo, oo))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Remember, `oo` is the SymPy notation for inifinity."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sums and products"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can evaluate sums and products using the functions: 'Sum'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "n = Symbol(\"n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADsAAAA9BAMAAADhUgydAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMs2Zq91U7yJ2iWZE\nELuNX9C8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAACFklEQVQ4Ec2Vz2sTQRTHv/nRpMnuklBPnhK8\niYdW2lMlpgjSBg+KFytEsgVbb017bEESUARBSaBKoafgqT25oCh4ykWEXsxB8OTFP8AmodpYLOPs\nzr7ZTXYz577Dznvfz763MzszPMC2KSB10HLckMeFm8AnPAwhQloFysh0xvFVGD0kzfE4MsCEpcBn\nmGgq8ABJBebfzrTHZytn/gjYGb/uJ5US0vMFf+3EY3806n+bOxuVhuLUecDTzLO/cnpyalWWdcQf\nL97XToI4zu6QqFVMcmU2KsekIZYn18M5ZpGIq+R5WGMDEpFyvdhi/xaJR7/JCx2/s5lQ3RV19keF\n8fako+JRlldho3aqwqiytorHmPJooeKrnvF2sOvWbDxQFcduXYX1XpCmrxdIzJnkeeM+briBseWp\n0ltGri6C6IIYh55lNNpC+Dmky6AqdiLtrSohGXfui+BjXYofpAekxSnwrUrf8OF3wm+YpBlFJ+Fw\n6fmrJvSWnuXA2Cb67La4ETO/msYAU2vrHU6i/UuO3eM74ZzJiHkXkz3UGLPzit4GMeeOGcY/aF0q\nGRwTXcTzQZkUfpUylv3dcEu2UO20whlX+b9+o9mLGjXeFbh9Bp76fx+9ZXcFlfGuoLIg1q5d3JEZ\nIfirlazH7d96BQjil699LSiIUcIXRXFsYjbiFL8cVnyyi/IKpfOuMGL6AvYsV7O7wrD9B0+roo4Z\nb2oXAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\sum_{n=1}^{10} \\frac{1}{n^{2}}$$"
      ],
      "text/plain": [
       "  10    \n",
       " ____   \n",
       " ╲      \n",
       "  ╲   1 \n",
       "   ╲  ──\n",
       "   ╱   2\n",
       "  ╱   n \n",
       " ╱      \n",
       " ‾‾‾‾   \n",
       "n = 1   "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n, 1, 10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAPBAMAAAAIUwCQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdMoki\nu0RRNjIpAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACUElEQVQ4Ea2TP2gTUQDGf+k1TZo/7eHoYvwD\nXaqeRShODaVB0aEVmqn+CYoUVEiGDuJicNAOgg6Kk5jVyQ5FxCAJgpMOtzg4NSg4C61WQRu/995d\nrt09wpfL+77fl/fevYPoylzNnddtbgFvab3Li0q7vQbtG63c46V22wqF9ls/zttv2TZDQkPqsPWG\n+n0VMBoy1SxM8rDf75eZ7qUbWd1tWeE9qV8xsC/A2k4SmpOLm7Yws37TfF8JmYUKF2AYPlEM010o\nW6Hu89sBXmVehcZ2ktAw4gqF6yrcD9mGDprtG8b+aCivT8sKX3qeTAfUA2fbjPnziI79aCifCb2/\nUG/BWI1iycTg20DMkgeF1nYZVyhayXiGq9da8EBDE5phD4owfvvVJSUwMSenNPNBobVdZnhAxz7F\noLCDV1NhB+404TXM3GLI14r1y8mHJ0EMaMnWdpmEjn0hfNZ+qTBTS3V8vO8q3CStMzBjTCvkj8WA\nKTR2lBnQsW+Yy939ppB71zstRhpa8iOyO7BsTCtwKNi1ZGNHmYSO9/C0du7rmi0EnQkdSEYbZPUU\nnplCIx9hw08Kre0yu+nooUzoP07Mzc0fqYlc0RLLOoklM0NvSyNW+sGeQmu7zG46KlyApwKHQu52\nczp/LzWQ0yaVyP3QuJWj8LybzNDaLpPQbg9nGnqtspMCx0OWg+kmHFCGc0z5pEyhlVVSP+NN10Nx\nts0kNOnZ7TOMliksVRTJb2w181Vz+N75knz1rN6eg7qzMla92HMAi8dXms52mQGt7P+9/gFEfua1\nt0ciqgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$1.54976773116654$$"
      ],
      "text/plain": [
       "1.54976773116654"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n,1, 10)).evalf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJ8AAAAPBAMAAAAIUwCQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdiTJE\nuyIU2bFIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACpklEQVQ4Ea1TQWsTQRh9223TdLPZ5FBPHmqt\nIEIrS62V9tJQo1Q8ZNEGoShEoQp6aKQeDV0U1JPVgwiCGMRKrZTsQS9ejIIHT1bP1u5FUA9KGmna\nYhvffNMUf4ALeftm3puXmfm+BRqP9fQ5aczTYI49CYEfcx+V/BI4OKtU8Qj0Xzy9pQhzsosBnLn5\nJCeNLqXAvIpTfLUtaOj1nf1wPHT4HD8ELmMg1B5t9NCsFlMR1gfrD77CWAX6RqsUgLiHRb7OqUDC\nMHAEkQoSd4BID6K7YOW1R4yGDycvimaHgd2YSGKNqyM68ENIDucmAxXUgBLsbgxx2bcC4ikYVYhH\nwFqAyb+iotk+IBO8LZtc1gj8pPJgtTKQYG4AEwEn1JGLBSRSsCsQj4C94Vpa0WzKZSCvj0duBNZe\njZeB2ypQwV7ukGPzARANCxjyYK9APNqYWZ3VCoQx55ELDBRJ9JHNmo9OmDlmCZSAKd7Ts5NAPwr4\nVURsXTzaCKs+qRXNAHudTXGPoY3AuosTrgUGCrTmjFKS6uMyiirQU4HKc0CMaH+/rBXN2B4puq3u\n7UBVn+nyThUogBuXSgHVpi4jYKA+sngEoilMaEUYjVn+WGpucavK9xl4vchAU4ESM64TIl4ZBANZ\nFKMC5fEFmkLEtCKMKR7wE1hKbgey8abfpNOZPWcV5Bh4BYkqA9vT6eWj8QVEq6o5p8sCQ9RHRBEG\n7IAT8jL+CXzN+6GrSW2OcC2Mbap32ybH0tgteYhHgPvCF1E04xcbCXtYas6rI7N9m4tmJx0JFUi4\n4B7yEfXRkeOYTXkXvYH2iNGeRFQrmn2fmzmGWzBWgJbh2oiUaGY0YJmWfvsCVlZ9/O+yn4nz9REM\nnj9OJh6BF2NKV4qwqXp9DXb2TJmT//n5CzSjDuDy+pXbAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$1.64493406684823$$"
      ],
      "text/plain": [
       "1.64493406684823"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sum(1/n**2, (n, 1, oo)).evalf()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Products work much the same way:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC8AAAA9BAMAAADPFy0PAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMs2Zq91U7yJ2iWZE\nELuNX9C8AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABXElEQVQ4EWNgAAEhBgbOlQvATBRC2JWBYRdD\nCooYhJPKwBDDwH8BUyaVgfcjA3sCNgnGHwysG7BK/GVgnYBV4gcDO1YJoB38B7DpwOGqdAaGydj8\n0RzvycBlZYtp0iAUYf+PAB+R3cdx5P+/DhDY/19NAFmCgeH9FzA///8FVHGG9VCJr2jiQ1zilEfn\nFEiCQfOgwbsJvD/AfkWVYEwIYuCAhCaqBC/vHwbuD1h0MLB9YGBRwCbBrMDAvwEc0KhGMbAvYMi/\nsACkBU2i/wDDIm4BLBJHGRhatoHE0XWAxQZe4j0k3axHS1ccwv//v2lg4JX6/1+tAeFUBgZw2v3A\nwAdKwShpF1kRPdjAkg4rAJV02AGwpMMOkCW4rSUnw1WhSJzfwN7AogQE2gwMyBK9U5GKT2QJBk+G\n41iNYihkMGYEG6WJahTHB4aYRJgWYEkHBzwODLM2QHmgkg4GAOSmp5CzUioBAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\prod_{n=1}^{10} n$$"
      ],
      "text/plain": [
       "  10   \n",
       "┬───┬  \n",
       "│   │ n\n",
       "│   │  \n",
       "n = 1  "
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Product(n, (n, 1, 10)) # 10!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Limits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Limits can be evaluated using the `limit` function. For example, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAPBAMAAAArJJMAAAAAHlBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAACGjDitAAAACXRSTlMAVO8Qq5l2zWYZcMvdAAAACXBIWXMAAA7EAAAOxAGV\nKw4bAAAAHUlEQVQIHWNgAANGZQYGk5DJQDYbqQSr03QPsBkAJYgIYEZbtZEAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(sin(x)/x, x, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use 'limit' to check the result of derivation using the `diff` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAAUBAMAAAD4uit9AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMnZUZs0Qu91E7yKJ\nmaurDqYVAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACz0lEQVQ4EXVVX0hTURz+rtvu3bybWRD1pBcD\nH6rV6KHCoIYUBCqsh1ERxCWIIKRECqFBDCoifBk+SQSaYCARDJIMIRiDgihpBeKL0YoKwgKtSFaa\nfffsnvtnzQN35/t9v+/3nfu75547oHZMeokub1AX60kPHcxXA2XMJfU+FwNNtsLL+fGUL1yoRsqK\ny4Z8FmrKzdRHp3z0WV8kgh4/VbTDgOHnZRQsSSTmqOELrWDQz5y3w/UMw76GoI4Kvb7RcdGzDhQg\nlKvG6xk+9stxEsq2ztTUX2x+sGmXwWQDW1DbFoaKOPMG+j3E7JakoTo/k0Bv23NRR32c8riBaRPD\nE0oSeItzQBangZuG/ocCjWQvjho3UOhAwyKCKZIc0nA6odxXBqEZog64BEQDo9gNtT8+R90R3DZh\n4CpwBfhJIpwAnuGVeUBPzELrQyBLkkMaphFYChegLIk64BrwMJbCAFSIF24/wss7YBleBr6zsDEH\nmDjORjCGDQaURZLRdPrEeDpdJrvKsJWLrog6YILyRkOUbjGtHNSnayXLcMA1rKLIL7Q2Vw0ptO8w\nYi16iIsuizphiBFTWQIiZaZo+AjBisfQapkN8YeNbKcsS8hhGzp3uCrqRMuYRcMocFDohrEH+Ogx\ntDZlLzejHVrZoms3JU3vxhIiFVEnNoUyagMlNMHalA4TGatfu+UoxT+0RR75WF+EuxQrUMUhN2U6\niRfKXYQKog6YYW4OI0ls7e68RTyPO53duZa1zy1r7/f9LosW1Q/t8cN8/l/jfI9CzVRxSEP12848\nnrz8IurID/O6UHyXRyk4zkeLY7z8w3P0+BQhT4I09Iv5muUtZlbStQeNfI/MfcJFLlm0Q1UUypw7\n8+PQlFIrkogaEjmzJiuvo599p5zEOiCDcFIzZLLO58v5wA7Fm3kSpb2s+G+eQqTttcNmHOSCSRcC\nXd6gLq79C/gHf4qzfkFAyyAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x y \\right )} + \\cos{\\left (y z \\right )}$$"
      ],
      "text/plain": [
       "sin(x⋅y) + cos(y⋅z)"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFMAAAAUBAMAAAADwRznAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHaZIu+JVM27RDKr\nZt2dj8xZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlUlEQVQoFXWTPUvDUBSG31jbfDUxFBQEh9BK\nXYRmEkXEiBRRUDo46RJaEXEKgrMZHDo6uAiKXXS0/gMFN0EIRZyLCK5qQWg76IlJ9V6jBxLOc86T\n+8G9Af6Lfp/t3LPwO1/kCmmbQx72ORQ8DjnQLA5R5pEl3WYJGOSRpRUWKJdqEHImigYgTFRcDGW3\noY41PGrl6MmML+XNSEhYSIklFKhcdNVV9QmyOQw0iU/oa0d71L1I0DwsJDwcUasKsas7ULtnBkzi\nZyBlpF5FOxLEJoykiTcaoUXtKxd419ujlGKNapAO0BPUF6BuqF1AIR17NaAtbH1YoQoMmJSFQqBO\noq/EjNqag9YhgRZA01zSKxSUJnAM+ZoKVUBMWlA6O8AdMW1LNAroMyKBtoUp1H1qFX1sqOuQnF0D\nh8QVmtk9xXJPSDjASHnWppZwk7cxv3mL88ZDjfiCOtnMDI0SClKwFlrMH8EebCDQ6aU9IdhFLL6v\nSyTQddF92Yx5QSFYcBChEFxCJTv9VYm9elc7FGQ7JvwUYj/MJ3CTXM0O35peAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y \\cos{\\left (x y \\right )}$$"
      ],
      "text/plain": [
       "y⋅cos(x⋅y)"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(f, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\displaystyle \\frac{\\mathrm{d}f(x,y)}{\\mathrm{d}x} = \\frac{f(x+h,y)-f(x,y)}{h}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "h = Symbol(\"h\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFMAAAAUBAMAAAADwRznAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHaZIu+JVM27RDKr\nZt2dj8xZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlUlEQVQoFXWTPUvDUBSG31jbfDUxFBQEh9BK\nXYRmEkXEiBRRUDo46RJaEXEKgrMZHDo6uAiKXXS0/gMFN0EIRZyLCK5qQWg76IlJ9V6jBxLOc86T\n+8G9Af6Lfp/t3LPwO1/kCmmbQx72ORQ8DjnQLA5R5pEl3WYJGOSRpRUWKJdqEHImigYgTFRcDGW3\noY41PGrl6MmML+XNSEhYSIklFKhcdNVV9QmyOQw0iU/oa0d71L1I0DwsJDwcUasKsas7ULtnBkzi\nZyBlpF5FOxLEJoykiTcaoUXtKxd419ujlGKNapAO0BPUF6BuqF1AIR17NaAtbH1YoQoMmJSFQqBO\noq/EjNqag9YhgRZA01zSKxSUJnAM+ZoKVUBMWlA6O8AdMW1LNAroMyKBtoUp1H1qFX1sqOuQnF0D\nh8QVmtk9xXJPSDjASHnWppZwk7cxv3mL88ZDjfiCOtnMDI0SClKwFlrMH8EebCDQ6aU9IdhFLL6v\nSyTQddF92Yx5QSFYcBChEFxCJTv9VYm9elc7FGQ7JvwUYj/MJ3CTXM0O35peAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y \\cos{\\left (x y \\right )}$$"
      ],
      "text/plain": [
       "y⋅cos(x⋅y)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit((f.subs(x, x+h) - f)/h, h, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "OK!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can change the direction from which we approach the limiting point using the `dir` keywork argument:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABMAAAALBAMAAABv+6sJAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEKvvZom7mXYyzVQi\n3UQ6SGZXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAaklEQVQIHWNgYBBgAAIQwaj82YGBIayogYGB\nbQLHLwapDQxTGRg8GRj2J6xkYGA5wACUYP0LJBgcQEyGfBDRAGYm/wNqd2BwZGDgiDE+wMBxgIGd\ngSGcYb4dgytQolxtAwNjvXEAUDncNgBJUBUwaYAbUgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\infty$$"
      ],
      "text/plain": [
       "∞"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(1/x, x, 0, dir=\"+\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACMAAAALBAMAAAAHCCkxAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMqvvZom7mXZU\nIkRJD0iWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAfklEQVQIHWNggAMBEAtMQIUYw74VMDB0Lt0A\nV8LA6cD9iUHoAIMHQqiEgeH8BBUGBvYLDELGIKDCANTA8RmkC6gdCkC8+SAChCEAxJr2j4GBsQAm\nwlDIwMDdm3aBgfsCXIiLgaGLwT+PoQIuwsC4KvIAA+P6tAaEENThAgwMAMSLGqu/gFQwAAAAAElF\nTkSuQmCC\n",
      "text/latex": [
       "$$-\\infty$$"
      ],
      "text/plain": [
       "-∞"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(1/x, x, 0, dir=\"-\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Series expansion is also one of the most useful features of a CAS. In SymPy we can perform a series expansion of an expression using the `series` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVoAAAAwBAMAAACiZ6/NAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWaJ3SJE\nuzID+9VZAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFlElEQVRoBdVYXWgcVRQ+m7s7+zObyUptXwo2\nWkQQlSENgeBDQy1BWrCLJmofqgNpCuKDEcUFiXQRBX+QLmhWImiDf0VE3RchqCXzYAs+2AR/HmMX\nwQcfJKlNGxur67nzs3Nn55xJ1kQ2DmRy7/ed78y3d+7ce2YA2jimfjSZ6OoIx8ACIwEw7psts+Sm\niWwtOUEnSZVTnKnEZVqCaL6xwnKbJ3I14086S6qSWaYZGIxxe5PJiLYCztn6dS4PO7ZjMW5tLtvW\n4Pxt7avTVzB2xLh9cPy/HFzIWbQn0J5hiKzg3ep2hpvtTLb24Ck2nJsJr8a4xVWBeQ7Yy7RDZIps\ntHGJpIQV4zZpCvY5ILO1B34DF2hBX13/g2QSo6NXyiSDYFdN56cJJ9owbjx5w/d0cK6W2UszEGMo\na2b5m8Wk2xA8cPyrx6yuRmM5Eu0wRvWNWisjThw+XwV4baXQymDfUcH0UYLaPCQqmQ9zE1QenhmE\nV6wzlAQxXsUI2oLxnl1OREZPpuCZ1+G0uZu5Cq9iBG3BAtILtIBnTHiOliDKqxhJtlpmGBLusUgY\nQZ65ykliVaRoUu8lcQZcqjMEsIzxNydBnFWFNIbtdrUhYYHlttc/J8wnQDOpOJ7ZoS3DGCVBjFeF\nBb953a4CNr4Oc3xvvnARZkmaZfKXupf1MqkBYFUt8U95/Z5dWP9kuWwtIug/MfAwHcsyYnhs/KXW\nPH6fVTkB5/a9tWrLVsqSZzzmivkZgPec9jY7acVvLzz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PiCvxTMa8qx/WJ66hDkCuKuKL0FSBrf\nSmboPFMjdYLwBG83vBIvCHHKvpONxhqI6nFKGoT+r1v/ACMLtG2aUvPeAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$1 + x + \\frac{x^{2}}{2} + \\frac{x^{3}}{6} + \\frac{x^{4}}{24} + \\frac{x^{5}}{120} + \\mathcal{O}\\left(x^{6}\\right)$$"
      ],
      "text/plain": [
       "         2    3    4     5        \n",
       "        x    x    x     x     ⎛ 6⎞\n",
       "1 + x + ── + ── + ── + ─── + O⎝x ⎠\n",
       "        2    6    24   120        "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By default it expands the expression around $x=0$, but we can expand around any value of $x$ by explicitly include a value in the function call:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAvwAAAAoBAMAAABwRjOsAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIl2mSJE3e9UMqtm\nzbsXyEShAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAJmElEQVRoBe1aXYwkVRU+1T3dM93z1/wYNtls\naJklEhJiLzsmJrDSLmM0LOLEB1GyYTpxkzUmOpvg+POwMhj/EAxNgKg8uB3ezQzBDRvRbKO7cR/E\nHUOERBy3X0xIRHZZQYLrZDw/t6pu3bq35lZ1v5hwH26dc+75zvnu6Tu3qm4NwPstZwX+kNPf4R6s\nOwZymK/e/4kc3qFrMRSiCwMpczA3vxgyGOJa3hgCrEO/oiuF5OoKfDY/sBgK8xQGMseji5VmfrIp\nxJcaKVMxQ3no5f/5bnCXT+7SPR/X3LxR889qKBR9gYQaU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2cH6Vy1dsMnZILy2YXJ4QPxGOMDw7+tiemDMYyRXYLGUdhbmLJD7xj+UurUdyE\nMKP/FomR5IHzbijJ308GgA6ckw0fIj7NllwolWt8IMH+LhdLn04IdL7L+OluoFZuRu49lqCh6USD\nJC9w0A9BrisfS1gGMz4nJKb9LMAPGZ4BSFOdacOb+VEq10cHwtf9uSWdkM93GX8O4BbBZzBOTFG8\no/76Pole4KkI5BIkmGX0sMXGpuTHxh8AnO6x3QmQj42JcMvR31YelOSqvDSQWKnHsijF2UiKBHog\nYvw/AGT97vC9MEKawsw6W5zEk/Ux0YZ+IiqEMeCpXmiE5fcEsNvreZwjX8lVmh5EFn+Bys94fIFa\n7vrj0p5Tq2lbYYtswYXhBHywkRu+9cx8JzeIAJjrbOHyE/4qPK5fbhXKrUABPqqPrD06dKRqjn99\nUsmCrT48XCQx5gpaQ5S/ermCbNeaRXJHmAORNLRQXh06hOvmnRE42G7Ap/L/zeAHxnUoqVPOjPC2\nIX4ZRnwFV/+Q5Z/o2RIUsk30C8F00IKueMrv4j8MdDx9dTfM9fQw5V+AYOjNB+ITLJ1aIXn4PyT6\n7Ja7Hcfy93Oj6BNf0Byi/MQVb70nhrr1Arycn7kdUfme3Z7D+iRUFnO4i+upYqsfc33hhRdOP1Lg\n1smbD3HF943zRfY9bY7X9TRlGPG6IdcBfhNoQzl/+ddw78/PW+WaGOSH8gEj48+BeuEuEERBKhkH\nPrmivpHL2+Z87w17n7fZs22TzaDAk4/KNTvIDm4dpdXP+PGu+V/TVv9M432Zo96DQcfb1eV4YXsb\n76O5295DvdwYkFyli1f6ubF8vsv4YO62AqlzJ3wf8P9Rgf8BNeLlKiPUeWYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$e + e \\left(x - 1\\right) + \\frac{e}{2} \\left(x - 1\\right)^{2} + \\frac{e}{6} \\left(x - 1\\right)^{3} + \\frac{e}{24} \\left(x - 1\\right)^{4} + \\frac{e}{120} \\left(x - 1\\right)^{5} + \\mathcal{O}\\left(\\left(x - 1\\right)^{6}; x\\rightarrow1\\right)$$"
      ],
      "text/plain": [
       "                         2            3            4            5             \n",
       "                ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)     ⎛       6\n",
       "ℯ + ℯ⋅(x - 1) + ────────── + ────────── + ────────── + ────────── + O⎝(x - 1) \n",
       "                    2            6            24          120                 \n",
       "\n",
       "        \n",
       "       ⎞\n",
       "; x → 1⎠\n",
       "        "
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x, 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And we can explicitly define to which order the series expansion should be carried out:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABUUAAAAoBAMAAAArnobcAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEIl2mSJE3e9UMqtm\nzbsXyEShAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAQSUlEQVR4Ae1dfYxcVRU/b3bnc2d3hxalpiE7\nbmskCjLdLglasMOyglKElSCgIXQSCPUvuwHrR2rpghFFQLcRI0K0E+Q/YnYRiEghHZHG/gGyxAgR\n2DImgN/QYvkoLYznnHvfu+/d9+6bd9/MX6Y35L577zu/3/mdc+++7ykAx8vxDPQ3A0/2j251H6hW\nrP9MCpZ0KHSUGkginTWTMynEKkhP3gVNHyiYqF88TNZzYlSKqDWwFOz30sv1zpXbBpfYS0iHQj+p\ngaxxy0y2ai9WIXrzzjx9oOgrjwiu18SoFHHrKxVtoJfuhl7AjL1i3rkgCUnmonN8ZolRk/f7UNhM\nCiRUmyp/yd4CJzb9A3Ht0iNXtvT9Nt4Bxs/S8di3o4DM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2} \\left(x - 1\\right)^{2} + \\frac{e}{6} \\left(x - 1\\right)^{3} + \\frac{e}{24} \\left(x - 1\\right)^{4} + \\frac{e}{120} \\left(x - 1\\right)^{5} + \\frac{e}{720} \\left(x - 1\\right)^{6} + \\frac{e}{5040} \\left(x - 1\\right)^{7} + \\frac{e}{40320} \\left(x - 1\\right)^{8} + \\frac{e}{362880} \\left(x - 1\\right)^{9} + \\mathcal{O}\\left(\\left(x - 1\\right)^{10}; x\\rightarrow1\\right)$$"
      ],
      "text/plain": [
       "                         2            3            4            5            6\n",
       "                ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1) \n",
       "ℯ + ℯ⋅(x - 1) + ────────── + ────────── + ────────── + ────────── + ──────────\n",
       "                    2            6            24          120          720    \n",
       "\n",
       "            7            8            9                      \n",
       "   ℯ⋅(x - 1)    ℯ⋅(x - 1)    ℯ⋅(x - 1)     ⎛       10       ⎞\n",
       " + ────────── + ────────── + ────────── + O⎝(x - 1)  ; x → 1⎠\n",
       "      5040        40320        362880                        "
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series(exp(x), x, 1, 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The series expansion includes the order of the approximation, which is very useful for keeping track of the order of validity when we do calculations with series expansions of different order:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMQAAAAwBAMAAAC8i8hXAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVO8Qq5l2zWbdMiJE\nibtHdKBDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADm0lEQVRYCcVW30sUURQ+2+zu7M7O6Ib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aljf5s2p9UYPVPBUFTpCVDtuAf\nEcr7xH4froTxzkrGzpHWQLZsvNEmzS+AdBPIFl+sjY2muOORlgogW1yxRrIREjnOFKRfdHX17TQ4\nWo0UXhFRjoVDb7JqLMcb/nJhvofDO3R9EBajpdIax4LS2mLR5Ij/kfoLzgzy5MB/1+MAAAAASUVO\nRK5CYII=\n",
      "text/latex": [
       "$$1 - \\frac{x^{2}}{2} + \\frac{x^{4}}{24} + \\mathcal{O}\\left(x^{5}\\right)$$"
      ],
      "text/plain": [
       "     2    4        \n",
       "    x    x     ⎛ 5⎞\n",
       "1 - ── + ── + O⎝x ⎠\n",
       "    2    24        "
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = cos(x).series(x, 0, 5)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAcBAMAAAD1rn4EAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACCUlEQVQ4EY1Sv2tTURT+Xsx7SV5+9FKh0MnX\nCm61obhYB99SHBv8A0wUwbFO6qJDUcShtCiCwcEIuuhglg7i0Afi4CBJ7SDSwS4OTiYiCCLEc867\n971cSfFdOOd833fOx7l5N0DG4+3vZpzUY5dxOpvhnR67jV6Yy2CpdPXQHaw23Pr/HSWVzLxSuJKQ\nf4C7O7P5ULSPaWcdKKb2VGe04G5/GDUI5IdJw+sDOYpJ50hwQWFxi1o8pc9NqvmBYVL9QNM95ysw\nxc1aR0twW24E3DVUqjG4w2oXKPFtespMvH/xkvC+oZah2PeJl3nDrWTg+2hE+CTF9PGVE4HoZkMz\nYlo+oPSZwpk/df4SVT5NBadVWC9uCTOGL3KPWp/ENxQzuBHckwG6YgRPeUM/FG4MO8J6DSoPKC5i\nTT0TCfTacFDqMvPa7Uff2u06wSeKhdecNigUHjOUs9qhMhUIBsyGsxEJlZ+s8gbgh2ROtEHuFQvG\nsMZrZrkVGyp/4j7lXghfLSInd0g2HPtFb7otQ2coP80NMKct9JWanR2ci6nZUBgtr+yFotF3d3+X\nB/mr2kDvcnR++pOmxoC3mxtRPMHffWlu4bqeP+SlTZdqTX5JKtxPISEntCiTasuSnPTfbukpqRyk\nmFChbtFJZNkSi5FFJ5FZS7xmsYnE74/J+e4YOQw+H2tU1RjJCv8Cl4Bl3Hr5MZEAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$x + \\mathcal{O}\\left(x^{2}\\right)$$"
      ],
      "text/plain": [
       "     ⎛ 2⎞\n",
       "x + O⎝x ⎠"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = sin(x).series(x, 0, 2)\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAcBAMAAAD1rn4EAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACCUlEQVQ4EY1Sv2tTURT+Xsx7SV5+9FKh0MnX\nCm61obhYB99SHBv8A0wUwbFO6qJDUcShtCiCwcEIuuhglg7i0Afi4CBJ7SDSwS4OTiYiCCLEc867\n971cSfFdOOd833fOx7l5N0DG4+3vZpzUY5dxOpvhnR67jV6Yy2CpdPXQHaw23Pr/HSWVzLxSuJKQ\nf4C7O7P5ULSPaWcdKKb2VGe04G5/GDUI5IdJw+sDOYpJ50hwQWFxi1o8pc9NqvmBYVL9QNM95ysw\nxc1aR0twW24E3DVUqjG4w2oXKPFtespMvH/xkvC+oZah2PeJl3nDrWTg+2hE+CTF9PGVE4HoZkMz\nYlo+oPSZwpk/df4SVT5NBadVWC9uCTOGL3KPWp/ENxQzuBHckwG6YgRPeUM/FG4MO8J6DSoPKC5i\nTT0TCfTacFDqMvPa7Uff2u06wSeKhdecNigUHjOUs9qhMhUIBsyGsxEJlZ+s8gbgh2ROtEHuFQvG\nsMZrZrkVGyp/4j7lXghfLSInd0g2HPtFb7otQ2coP80NMKct9JWanR2ci6nZUBgtr+yFotF3d3+X\nB/mr2kDvcnR++pOmxoC3mxtRPMHffWlu4bqeP+SlTZdqTX5JKtxPISEntCiTasuSnPTfbukpqRyk\nmFChbtFJZNkSi5FFJ5FZS7xmsYnE74/J+e4YOQw+H2tU1RjJCv8Cl4Bl3Hr5MZEAAAAASUVORK5C\nYII=\n",
      "text/latex": [
       "$$x + \\mathcal{O}\\left(x^{2}\\right)$$"
      ],
      "text/plain": [
       "     ⎛ 2⎞\n",
       "x + O⎝x ⎠"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(s1 * s2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we want to get rid of the order information we can use the `removeO` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG8AAAAwBAMAAADtMzlxAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACRUlEQVRIDc2Vv2vUYBjHv8klubt4XsMVOqdV\nCg6HtS3oIJhBORfx8B/o6XCLSG/TSQ8VsTjo2MOhFR0VuiuYyU0aFNqhFBwVRe78hagYn8vv5p6n\noA76Dnmf5/t9PnnfhDxvgGBUjjY6YZS/GvVDeSmb6/7HbJqJN7GVyUZC/aE1ooXCBq4ITiDrTdnd\nfcUXdWlJ5Z18T0BrFtcE/4AtGJFc+ST5u261YCmfJXB9VXJIrzragLXpCU93WCcUDcvwePs6Lguv\nrbbvxLSN9sYIp0zNnzmHZ9PzI04gKK3i1dIdzpvAJXuJM0KNNjkwHc4/i0XrAWeEmoLyGu9auMsb\nsTpmx1F+/pAXdubr7s48ySo/kpAJTOsgVPaF31P7mGSISFpYfYoGZ+vf9vS1DueE2vhUbZO1ldnJ\n+kWZ+78d0/7D/f07MOyn39h2tFW5n6R7RWDUT346CFCWb9JYcikcS40+pUavt/ym15uhGrGfqIwd\nyVuV+4nlkIBiP/FcDMr9JHAxKPaTxMVg3E+ntp4MS59z9dr2YzfVk2cMJGUGi02KbqUFaTQOI/Nn\nUJzUAQoWqq8A9W1WjGP6i7+P4/xc7aJAh1KDPQpfA8fcPBHl5UEAtlhwxZJB4ksDFB0WJPO2JaxI\n8kILNenU1r/IHK4BLQks0Vctjb0eTFcCtyWK9DowAQFUPRk0PRy/Pzf3c5YreQTN4fShRt/afprY\nD6DiQXXI5IZ2o/2yS8Z3zjzZvnCE04damU6ILnDeP8xUrPj+V0b+K+kXPYuKl+Zu0xMAAAAASUVO\nRK5CYII=\n",
      "text/latex": [
       "$$\\frac{x^{5}}{24} - \\frac{x^{3}}{2} + x$$"
      ],
      "text/plain": [
       " 5    3    \n",
       "x    x     \n",
       "── - ── + x\n",
       "24   2     "
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand(s1.removeO() * s2.removeO())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But note that this is not the correct expansion of $\\cos(x)\\sin(x)$ to $5$th order:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANsAAAAwBAMAAABqLhIyAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEdklEQVRYCb1XXWgcVRQ+s5n9/xsSKPSl2aRF\nn2K3IqgVdR6M+lKzCIIodbcpRF9i9skKggSFah5KgiI2+NAI+uCDNC8FtUJHqo8lGxcqWkIjtGB9\nkF1pqwZlPHdmzp17Z++d7G7ECzP3nO875zs7s3PvmQHYZcy2rZiIy9+eimEHp4rN4npMVt2txrCD\nU8VGuhOT9cI3MeRQVOzVPTeUZFzSASeGPT65GcP2Sx279jWFJt4ji8/m1kUncKbhDQ4PbRhVWKhR\ndu/NHIPUHWJhw+bmsMaIBaVtSi7skEXzEYDfAvsIjPPfRfTAc2kRRv72sw445h/R/F8AHnd88AbM\nWFF6YD/b5eUydvrnaP45i5c7AfNRdig/04XRg9P3VAqzJ22FwLJlTD7w7Cyk5hsKdnCo3jAa6bcy\nK+rM5F3YB69XltTsEOjbkLJS3ZytTs1U4QQsWJ+o2cHRYgsMyK7rErcALPhIx6rwuXtVKGFTzChX\nyI3MiRYDfo+gcW629kwMnWvBEwAbjibkczBtKARLRRPjw98F7EEYhYQ28grAoZx1GBLKRVVoQcL+\nONGBCa1AQBTo7/gVgWRVE26enmsv1tcuwVPKgKfn5h9K7uQ7ZlNJC2CWfu4O28pfFhjRzLquuzg2\nOfqDWu+c6/5p3D8xpWvkyc19yx94et8HquY/8DxAhoqLtfZuTyUvXHFrqGN2AzFjB8o18J+wvevL\nCiOVlyw4vIJgqkXMHSg3weyQ28+cq8RGcbpt3MRFxKRLa5TxIbs6eIfcfmaupw4mOtllHRJ3eVxJ\nFoW+CJ+heY3cfmbS08QSnWnlMCLPru5NHpq+ik8m3IeHt/FzPMYgPU0I0XWHBeS38fQjHn7nQANH\n3YK4jd8PojPpkR+Zib7u3cFSC+mLeIidA7epuI1fFiQ9GeUe0Zc8ZKOG0/t4iJ1jpsY3fuPsuziW\nHBaMq1waCKVWV8/eWl2tolmWONftyDT2ehxfstMZPMTOMbOGgHbjR04c9PNFTLCJ9l5jCrcZw65O\n7Bx4dTEbvxccnkgvRCSL6AV2B/YzYb+c0Dk2bNBv/JIYOqQXxQOf6HF8czMveOAjeBY7Bz6Z+o0/\nKkt6UTzwiU67R6fbtgfiOpM6B65D/cYflSW9KB74nL68fMbxMbbOxM4Ru6s8OfeVpMz1CM1OFH4i\nW3mvS94/GIb0fm6EnNmC883Qxf3BFrwcvuyWXLcRQhLtw0WBRsSgfhQmhVYCe9Ri6MrWWBtTsycP\nyWjUK2xLSJo9s7qRvAnjKzoSElhuRMsScZQMb844ktvjyDdTovsrt1/KeU3yehzjdA/EAa/cqSmH\nA0oj1xJgc11wek3zlc1ekBBWLm+Z4WclEfL8qeAWLcFRma/WVKiHsXI4vvDO/9Gp1PNpx4WDctdt\njuzRwPfyfM93Mtdk5R4G4ROeM0Ma5e5u5W4B+K17yApSWmkdMl7XklBy2NXhY7dE/p7ndBPOV7Qq\nrNwxSN/QBgxMHN/yu5YqsfjYXw+CefXR3Z5tVe7/iP0Lu0QQYvWiWkQAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x - \\frac{2 x^{3}}{3} + \\frac{2 x^{5}}{15} + \\mathcal{O}\\left(x^{6}\\right)$$"
      ],
      "text/plain": [
       "       3      5        \n",
       "    2⋅x    2⋅x     ⎛ 6⎞\n",
       "x - ──── + ──── + O⎝x ⎠\n",
       "     3      15         "
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(cos(x)*sin(x)).series(x, 0, 6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Linear algebra"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Matrices"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Matrices are defined using the `Matrix` class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "m11, m12, m21, m22 = symbols(\"m11, m12, m21, m22\")\n",
    "b1, b2 = symbols(\"b1, b2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGgAAAAyBAMAAABCJ4MDAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBEqyJ2u93N\nZplQnf8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABo0lEQVRIDe2WsUrDUBSGf5s0VmNF1MXJbuJS\nKT5AFeuewb1FfABXnQoubnYSfAAFFyk+QcAH0c2hFqpg7Rbvudfc60lPh9ZJyIEL4f73a8pP8hFs\nJh+YanaSd6w1DqdicNSoYX06hE7v55ApTRcRbF3enAXbd1KPUqahwuI9mteoAX5slsN5Vn2IVKSh\ngzDGVQXP8F+7ejkGLCu059WvGihqtlCPcA54XbMcxbKw7Y9SCHWgB2xIEMvCVmlooTfgEcGoKNwJ\nLIP3aaFVFIdYji8kiGUIOymk7lkeYKlSESCeoaoYU0TQxcIpvP6eAPGs/GIhujAz3l6amJKOcaI2\nMq+Gt6JCtaRR+/7T7u0YVOp9dWhJDO3PJclgDJIOC3uZvyecELZy6KeUvIg/FyEJMX3kpExX7oRI\nMiRhuuGZJEuSIQnz11hZUibKUsuQXnk3VpaUibLUMuSQlSVlsixJhhnIylKLUpIlyTADWVlqUUqy\nJBlyyMlSi1KSJcmQQ06WlImyJBlyyPVImSRLLcMJsqRMlCXJcJIsKfsvspzp022Wj8RvbKDHm//7\nt/sAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}m_{11} & m_{12}\\\\m_{21} & m_{22}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡m₁₁  m₁₂⎤\n",
       "⎢        ⎥\n",
       "⎣m₂₁  m₂₂⎦"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = Matrix([[m11, m12],[m21, m22]])\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB4AAAAyBAMAAAC5cHbcAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhC73c2rRHaZ\nImaqCQggAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA9klEQVQoFWOQ//+JAQb0/39kEHZxhXEZQlwM\nGUTgPBDDEcRnTSyACYL5DBwTUPn8Bqj89QGofHUYF2IeQ+fuw1ARiPk/AuIvMHiAhMB85q8M/Ao+\n0+F8ngaGeAUGczif4wDDegMkPv8DhvMByPwFrHIMSHzOB2wHkPmsp88BzUKYB+Rg4RuCBCH+BbHu\n1M9G4YPEkOXpyKdLfDAdOwrzHzg+dBlmwPjg+Khl8L8A9T84PqoY7i+A8iHxwWAPTAXg8OMHxwdD\nNUw/JD6YDsD4kPh4A+QihTeXApcDMt/D2AxmHkghg/z//0ASET9gQSL46OkdLT8AAPfcTiuXVltr\nAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}b_{1}\\\\b_{2}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡b₁⎤\n",
       "⎢  ⎥\n",
       "⎣b₂⎦"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = Matrix([[b1], [b2]])\n",
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With `Matrix` class instances we can do the usual matrix algebra operations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAAzBAMAAAB4eZ5HAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBEqyJ2u93N\nZplQnf8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFPUlEQVRoBdWaP4hcVRTGv51/WR2zBLUJCJlO\nBYlZUqlgEoyd6BYWdhkWOwtTmsRiwMY0ZiqDVjYGYiGrhSQQyKCFhVNaaxoRzAprwBir8Z5z7znn\nnXfv242F8t6Ft3vPN+ee95u3d+e89zFAcRz/cquot0k8trqX4/Rmhxa52iLl+dUfeOLsqznReDZ4\nkKstUt48u4knSzzj6fr9kt4i7UyZHOj/2SLKEkoj+XheSm+R1kh+vALZ/5/exQuVcx44bSI/fKey\ntFPk23jb0DtAPnr6w08ujJ69hsF3Jz/Pybffu3x1vv3p1F7JFXtNZ3lSrnBy2i1KoRVyBfC7pffo\ndZz7GJtYW632dB3kmk++mA//nvaPAK8Bvd9+AVThKKiloUm0jA+n8FJel8iVAoMFQN3cFIpif/fk\nr4wXuDLBz7XzJ/LBiVtYv4fDe3j9EvAM3ocpFJFaGJZECXR4hZbGkciVYvDrDribq0JR6u+efOvc\nFKe2cDEUX8QjXNvl8oenlsvzwHB4nz7mD30GvATcwBszUygitTAsiRNCkld4KfDccvnVcvl9KGAU\n/R1wN1eFotTfPTlOAXeBo6B3S0ccslv6e9jYwdqcyb/BlSlU4ahMbklC7hVeyidK11wpQOTcz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jM+W0iCfPzQrqXvvYF7lBRIo3\nkfRcNskNoryQZYcZ3bfU7l08uctuUVAx5ZSqG+QVU65j5IpbmZwpf0ukktHOKX1LpPjNnHbiVqjC\nN3P+AQTjoqnEhDFNAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}m_{11}^{2} + m_{12} m_{21} & m_{11} m_{12} + m_{12} m_{22}\\\\m_{11} m_{21} + m_{21} m_{22} & m_{12} m_{21} + m_{22}^{2}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡    2                               ⎤\n",
       "⎢ m₁₁  + m₁₂⋅m₂₁    m₁₁⋅m₁₂ + m₁₂⋅m₂₂⎥\n",
       "⎢                                    ⎥\n",
       "⎢                                 2  ⎥\n",
       "⎣m₁₁⋅m₂₁ + m₂₁⋅m₂₂   m₁₂⋅m₂₁ + m₂₂   ⎦"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJEAAAAyBAMAAACufiRQAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhC73c2rRHaZ\nImaqCQggAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACnklEQVRIDe2Xv2sTYRjHvya5Jj3TJqjgIOht\nKnaoOHRwqNAKDg7n4qQEBxftEP0HPBAhBYdOdQhIKO7tbDsEHFoRasBVMf+BJaWggXg+z/O+6f16\ncx6mk+0LB+/7vN9+evfcm3wILvk9jD1yvl/F2cXbY4NgLS5UcW58DhMKQrIe1TPh7p8fHVMklFZG\nR8I7y+FFdK5JldloOb66qQv78Y1grUnrblAyzTTJPjBtqpomXR6dkB1NyqW0U5OWNz/IX9hXv202\n7WtP4mBNKjW3VBsMOUWyfrq1Du4AuYmnqL3HdXqpnroUU5Nqr6wBZpbcWI4r+hTkD1Bx7r4BFooe\nvjv4gcLHulwKBE2ad9HLdSa9aE4qmlT2UHMwB7i1Fii+CuSpJXzRuNJoPGs0+ADswOoVO4VBNCcV\nTSq1sT7LJMwD28CFCInK+p5ew94vtqb60ZyqqD5VuvjsCmkHeA57YIXvKSD9RpnOAfWC7i6Uk4om\ntayLENIZWH2UvS9mUh/3ukBxA4jkpKJIk92JtpDoxqf3UHIcM+ktlgDMANEcV4af4E+7NKc+2XWc\nXkF+95aZ9GCrC0y34zmuaBJNaHDHD0fo3VFNd1x21/DuMKXejFTU06kdOo/ByFcpRZcaD4cT+t8v\nbzwOVpxRlRDp64tmkJja/rXBV1AZzk75/t5wTg2jjKqESMH2P81OSNnadhz6dGJOPgv/jTnZhgWP\nnkiG/qYzmJNzqeZkG7I9o6SkOTmXbk6xYQZzci7dnGJDTaL70k+XNCfn/mJOtmGCZDCnWJNdqr4L\nKklzsg0TJIM5xZrsUkUymJNtmCAZzCnWTDUn2zBBMpiTc+nmZBsmSHImoubkVao5xYYZzMm5dHOy\nDbOYk3PHxJxH96vsyH4p/gHeHTH4ApAfnQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}b_{1} m_{11} + b_{2} m_{12}\\\\b_{1} m_{21} + b_{2} m_{22}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡b₁⋅m₁₁ + b₂⋅m₁₂⎤\n",
       "⎢               ⎥\n",
       "⎣b₁⋅m₂₁ + b₂⋅m₂₂⎦"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A * b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And calculate determinants and inverses, and the like:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKYAAAAMBAMAAAAaIdvMAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMARImrIna7EFTvMt3N\nZpneUCSWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABq0lEQVQoFWWTsWvUYBjGf0mvvVxij3CjDgbU\ntTh4Xexwg4KTvVJ01kHdSv4AoZ2kUugVwdmOHYqeopOCoVPpn+BghUIdesKdVhyv7/udfm9iH3jg\ne35JHt43IQRXbt1rB9ce4nWe+Et6aN24vdxt3U8NniPhzCNWl3gOcTGxkbmVHHVF2eNu/XcabcEu\nhMffwROXhO4kBYsZh8RHfWcjYWeqUFcq47VP1H4yO+T1TbjKAkY0Kc1XU3o58xD1J/Yk6cSnau18\n+lF1APX6iOgPUw9gA97zpmNEk1J6cAIvrdOTJK2N1HJTSdGQZp9G13W+ZTHFE5e0cwDvCE7rfk4j\nOpBzqZJmQZJxuZO7iXRHI5q08wWyTbO4Y52ekMg06rIaGfK6BrW1SecHMIIk6ZTV5H1fyDLfaYQ5\nKVOXJcsewl7onib8hq7/l2iSzqDP9HWiH9u+08is3KKu6BIsw+aXSedXuWZEk+7u9e+7e0CLi85G\nKiedKAu2jblU7dySDyL2ivfXn6g9+O8g/8nu+rPcqEtCvWonv7pqD2iMx0O1kcrp7uc2r8bjEtMk\n9AyNtKqM6qgiUQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$m_{11} m_{22} - m_{12} m_{21}$$"
      ],
      "text/plain": [
       "m₁₁⋅m₂₂ - m₁₂⋅m₂₁"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.det()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgA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h/1f2\nMbqzohXqXU8mOVmm/oHyoE7/Lpeanj6h/y9AOduPWZP+N9e1Lsump08IevzEMTv8yFaFT58oa3nL\nNY1lLT9ObexMiHqmNWyqHoi1Nf8PHzi4lSipunoAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left[\\begin{matrix}\\frac{1}{m_{11}} + \\frac{m_{12} m_{21}}{m_{11}^{2} \\left(m_{22} - \\frac{m_{12} m_{21}}{m_{11}}\\right)} & - \\frac{m_{12}}{m_{11} \\left(m_{22} - \\frac{m_{12} m_{21}}{m_{11}}\\right)}\\\\- \\frac{m_{21}}{m_{11} \\left(m_{22} - \\frac{m_{12} m_{21}}{m_{11}}\\right)} & \\frac{1}{m_{22} - \\frac{m_{12} m_{21}}{m_{11}}}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡ 1          m₁₂⋅m₂₁                -m₁₂        ⎤\n",
       "⎢─── + ────────────────────  ───────────────────⎥\n",
       "⎢m₁₁      2 ⎛      m₁₂⋅m₂₁⎞      ⎛      m₁₂⋅m₂₁⎞⎥\n",
       "⎢      m₁₁ ⋅⎜m₂₂ - ───────⎟  m₁₁⋅⎜m₂₂ - ───────⎟⎥\n",
       "⎢           ⎝        m₁₁  ⎠      ⎝        m₁₁  ⎠⎥\n",
       "⎢                                               ⎥\n",
       "⎢          -m₂₁                       1         ⎥\n",
       "⎢   ───────────────────         ─────────────   ⎥\n",
       "⎢       ⎛      m₁₂⋅m₂₁⎞               m₁₂⋅m₂₁   ⎥\n",
       "⎢   m₁₁⋅⎜m₂₂ - ───────⎟         m₂₂ - ───────   ⎥\n",
       "⎣       ⎝        m₁₁  ⎠                 m₁₁     ⎦"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.inv()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Solving equations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For solving equations and systems of equations we can use the `solve` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAUBAMAAADYerbFAAAALVBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAOrOgAAAADnRSTlMAdt3NMolEEFTvq5lmIsfa\npuIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAB3SURBVCgVYxAyYSAEDqsxhBFSA5QPQ1bFMR2Ljs4C\nVFVVu55jqGJfvQ5NFQMjpioGBrlBrqpYCQSAgTuYXV9ngBb+6KHKvfLxGgYmdVRVu+ZZHUCNbbB8\nL6oqMA8lTYBFAohRxS5AjCoeLIqA7hJSwSaOIiakBgD0ZimSClhTrgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left [ -1, \\quad 1\\right ]$$"
      ],
      "text/plain": [
       "[-1, 1]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(x**2 - 1, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjEAAABLCAMAAAC2lyZIAAAAPFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo1xBWAAAAE3RSTlMA\nMquZdlQQQOkwRM3du2aJ7yJs4cVMPgAAAAlwSFlzAAAOxAAADsQBlSsOGwAACPhJREFUeAHtnOna\noygQhYkmTk8WTcb7v9fBpUpFwTosytNJfjSYTlEvh/MpIom6tP2rUPJXM4Sk+FcOYXwyBczQppHI\n4zCiXnD2iLlJjktbXvXrBrA8gc8e9dEcmajvZ7LFy113NilapS7thXomLR/SDx74uRyZqPt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b7Jj++yIv65SElVJP\nWpOd3nLX4ABuTsoEZ4ADGIkrNja8aTwiaW6xY+ru62fOie8g1h394SA4gAdFnyBFTHAGOGBC4pqF\nDW8aj7Dpgre0FSF2zF0/lJRsjnmiq8JwAA+KEjLBGeCACYlrFja8aTzCpgve0laE2DFVW6j7/mbu\ncv8jLGpfgQNm4TImOAMcMEPi6jYb3jQeofczbY4V3tJmhNgxSk/c6ddeWJZV5YoaBg5YpJQwwRng\ngAUSH2yx4U3jER1Aytxyx7xaxZtjWBaj0n9p7SOYHlMcHECBQylggjPAAUskPtpgw5vGI/r8KXPL\nHaMn4HsT32FLJ/ATiHAAj8dQ2WeCM8ABBhIfrtnwpvEImy54S7YIuWPq9rbjmM+zaZqy2PkUS6p3\n3aABs9i+ussEZ4ADTCQ+XrHhTeMRY/aUueWOubSvndugx7AJU+4YOICHY6zsMsEZ4AATiY9XbHjT\neIRNF7wla4TcMXqjqvB5D4uWvpIjE/X6TLaEuQHHPL1/Qoo0jF/myES9PJMtYW7AMS90+Z+kS1jm\nyETdPZMtYW7AMY18GwOJlrzMkYk6fSZbwtyAY27OzTGk07FljkykwJlsCXMDjrHvFSONji9zZCIV\nzmRLmBtwDCnxK79agZ9jvnr4PTr/c4yHaF8d8nPMVw+/R+d/jvEQ7atDfo756uH36PzPMR6ifXXI\nzzFfPfwenf85xkO0rw75Oearh9+j84Nj+q1QO/ulPBr/hfxdCjyHLXP6ywrX/uXx0zB/lyC/3uwo\nUA9GUf8DYe6QJALMc1YAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left [ - i \\sqrt{- \\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad i \\sqrt{- \\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad - \\sqrt{\\frac{1}{2} + \\frac{\\sqrt{5}}{2}}, \\quad \\sqrt{\\frac{1}{2} + \\frac{\\sqrt{5}}{2}}\\right ]$$"
      ],
      "text/plain": [
       "⎡        _____________         _____________        ___________       ________\n",
       "⎢       ╱         ___         ╱         ___        ╱       ___       ╱       _\n",
       "⎢      ╱    1   ╲╱ 5         ╱    1   ╲╱ 5        ╱  1   ╲╱ 5       ╱  1   ╲╱ \n",
       "⎢-ⅈ⋅  ╱   - ─ + ───── , ⅈ⋅  ╱   - ─ + ───── , -  ╱   ─ + ───── ,   ╱   ─ + ───\n",
       "⎣   ╲╱      2     2       ╲╱      2     2      ╲╱    2     2     ╲╱    2     2\n",
       "\n",
       "___⎤\n",
       "__ ⎥\n",
       "5  ⎥\n",
       "── ⎥\n",
       "   ⎦"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(x**4 - x**2 - 1, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "System of equations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH4AAAAVBAMAAAByPkciAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAZpkQ3Ynvq81UMrtE\ndiLw+n06AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABrklEQVQ4EZ2UMUjDUBCG/+Sl2NI2uugqHcQu\nQiY7lSoiTpWAi4sguIgg1EFxDIK4Zupog6tDuzmI2KmbtFS0k6i7g1pEJ/HeS1KTl4iQGy69/97H\nXe5eCkApIJmd3XKOLSejieo45JTXBDybmSRWtQhNbZKTLLMlCXKYttkqoQukx/Cl2aEMSPEUsO6h\nMTzy//EXQMNwSyfiP4GuHeDLg5e7HvWo1USjMfXLc9DFVFboBHsnvufyYxbFplLV6Il57hDXv1lH\nnm+KbZPTP4Cm6a6u7tAgjNQw80QJz6L1dbuIbMvP61SfeBwB5zskMqRHOX4myjPsYrzn817/GKt6\nlyiQi+eRG6Lp+Dxofg0bOCGBvz9143DvW7Q+VAv3fhq4BKYN9/35JcoYj8gbv+kYPlsDLd03uj/F\nwP3p2td45rnA/CuWf1g81Vbujf8Q84dmM5qbuDrclR7KhQmedfevHnztQVviwsjYfv9bBHz/YBsD\nJ8CLhOxOJYEmINmovqS7oRlSD1FphwQKBP/X9896oeOLuArFPHA7Oo7oQlDC8k3fCQsUddpcyiT+\n/1sDfgDNr2XH9LJoSQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left \\{ x : 1, \\quad y : 0\\right \\}$$"
      ],
      "text/plain": [
       "{x: 1, y: 0}"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve([x + y - 1, x - y - 1], [x,y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In terms of other symbolic expressions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAAmBAMAAAAvsop7AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAVLsyIs3dRBCZ76tm\niXbIwtSaAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADrElEQVRYCc2XS0hUURjH/6N3nDvqjLNoUS5q\n6LEpiIEiaNUsQrA2gzASBGmCFdnDRbRooXcRQUqNGC1EsrAHlRUTVLTJXLlJUoggIXWgIEfIlKIM\nKzvn3MfM/c65M7OQ6CzOOd/v/L/vf1/nzh0A8G1i3T9or9pNE63RmuR71k/OGfmxmIfmP0iMAu3a\nwF3KgOn5GBBeNsTKhagsCNxCk0S1w0hKkIJzcf8CZaiL+BMM7uMdcN0Qg6vrGkGvC/CgcgKPJUiA\n/gDBKGHAQ1RFGAz8Eiut0ro4iFMSVh0ZFQWXUJFRQBP9FMMgXWfxIPSvElYJqagyilRMAU00JAZF\nHf03fAs0jcHiLTWBDZKKQbOZVirDRZQl1tBEdgd8lNE4FcEWX5zQmhGA30N24XK9mDrdIYym7cNy\nYD/0K07gMfFnqttCdC2YxsUYh96G3Z93DrfTvND71xRJsT78Zv8niU6NZQTzNpRSVgf8p4brV+fs\neJXSznAVDVvEsS8XOYNVNBSvYt8iM9Tnn3RMc+OKtGRf2PDyADTx89AmJcpgxmCsIsG6SxjNiHdq\nF4/crbDhRC3CCyxBv+3OUkZd7HS0BoOtvcOMIb1ZrJyChlrkKsqilrLooLUZqI1wmYGGfHXNCm+c\nvE0mjyeTB/lUMH4y+U3HI9RkcsQR6Y1HWGuNsaVcNVTfRPdmU/0nl0RmBc8QgSXs4VVLa2d7gPF2\nri2Xf43sEoUNgwnM2cqiY5i7hJZYt5bd+FkPfWHDsjS2eSTKuHOEMZ1dzMBi2YLGAxR/SlMJrnNa\nMGp+OJT0lG4VafeY6fBsdkwExfdhxTHHjE/0F9lvApSyD82tM+QqYAZa30bnSXAuaX2v+ICl24fd\nxbxmifII23p2Ne93aTdCP+yc89ZET2OGP2AT9oIYnyLFod1skR2L0anmbfgcuO/KYUGVgcob7Bpm\nXAsnsD0/tkT5CHCqeRveAV7G3FmobEYVe6yr3bgj69JZIrfGqeZt2GTIhv4lYeiuRSOlyKnmbcjq\nnDZoMfai53u2WFOKzGqFDAOqr9BO9wOjtlaJrGqFDBUbEihlrylFVjXTsEV5oH0KGuxRQIqUIqua\nadhIU3gcVtXOqpSUqURWNd38MzMeoTksXgctTrGvB3spk2KlyKoWMn+SgvyjhrTyHoTjhGE38JEy\nKVaJ7GpfRkx57QEprW5q8hmF2smp/mYKaawUWdV2HbXVZ+yJMzatrHx3AmviZ58PzRTSWCmyqu3g\n4r9Q1gIGAlZHdQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left \\{ x : \\frac{a}{2} + \\frac{c}{2}, \\quad y : \\frac{a}{2} - \\frac{c}{2}\\right \\}$$"
      ],
      "text/plain": [
       "⎧   a   c     a   c⎫\n",
       "⎨x: ─ + ─, y: ─ - ─⎬\n",
       "⎩   2   2     2   2⎭"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve([x + y - a, x - y - c], [x,y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Further reading"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* http://sympy.org/en/index.html - The SymPy projects web page.\n",
    "* https://github.com/sympy/sympy - The source code of SymPy.\n",
    "* http://live.sympy.org - Online version of SymPy for testing and demonstrations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "application/json": {
       "Software versions": [
        {
         "module": "Python",
         "version": "2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]"
        },
        {
         "module": "IPython",
         "version": "3.2.1"
        },
        {
         "module": "OS",
         "version": "Darwin 14.1.0 x86_64 i386 64bit"
        },
        {
         "module": "numpy",
         "version": "1.9.2"
        },
        {
         "module": "matplotlib",
         "version": "1.4.3"
        },
        {
         "module": "sympy",
         "version": "0.7.6"
        }
       ]
      },
      "text/html": [
       "<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]</td></tr><tr><td>IPython</td><td>3.2.1</td></tr><tr><td>OS</td><td>Darwin 14.1.0 x86_64 i386 64bit</td></tr><tr><td>numpy</td><td>1.9.2</td></tr><tr><td>matplotlib</td><td>1.4.3</td></tr><tr><td>sympy</td><td>0.7.6</td></tr><tr><td colspan='2'>Sat Aug 15 11:37:37 2015 JST</td></tr></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{|l|l|}\\hline\n",
       "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
       "Python & 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)] \\\\ \\hline\n",
       "IPython & 3.2.1 \\\\ \\hline\n",
       "OS & Darwin 14.1.0 x86\\_64 i386 64bit \\\\ \\hline\n",
       "numpy & 1.9.2 \\\\ \\hline\n",
       "matplotlib & 1.4.3 \\\\ \\hline\n",
       "sympy & 0.7.6 \\\\ \\hline\n",
       "\\hline \\multicolumn{2}{|l|}{Sat Aug 15 11:37:37 2015 JST} \\\\ \\hline\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "Software versions\n",
       "Python 2.7.10 64bit [GCC 4.2.1 (Apple Inc. build 5577)]\n",
       "IPython 3.2.1\n",
       "OS Darwin 14.1.0 x86_64 i386 64bit\n",
       "numpy 1.9.2\n",
       "matplotlib 1.4.3\n",
       "sympy 0.7.6\n",
       "Sat Aug 15 11:37:37 2015 JST"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%reload_ext version_information\n",
    "\n",
    "%version_information numpy, matplotlib, sympy"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
